<commit_before># Resources

Unfancy resources embedding with Go.

- No blings.
- No runtime dependency.
- Embeddable builder.

### Dude, Why?

Yes, there is quite a lot of projects that handles resource embeding but they come with more bling than you will probably ever need and you often ended up with having dependenies for your end project, not this time.

### Installing

Just go get it!

```sh
$ go get github.com/omeid/go-resources/cmd/resources
```


### Usage
```sh
$ resources -help
Usage of resources:
  -declare=false: Whether to declare the "var" or not.
  -output="": The filename to write the output to.
  -package="main": The name of package to generate.
  -tag="": The tag to use for the generated package. Use empty for no tag.
  -trim="": Path prefix to remove from the resulting file path
  -var="FS": The name of variable to assign the virtual-filesystem to.
```

### Optimization
Generating resources result in a very high number of lines of code, 1mb of resources result about 5mb of code at over 87 thousand lines of code, _don't worry, the size of data stored in your binary is exactly same as the resources (eg. 1mb of resources only increases your binary size by 1mb_, compiling this many lines of code takes time and slows down the compiler.
To avoid recompiling the resources every time and leverage the `go build` cache, generate your resources into a standalone package and then import it, this will allow for faster iteration as you don't have to wait for the resources to be compiled with every change.

##### "Live" development of resources 
For fast iteration and improvement of your resources, you can work around the compile with the follow technique: 

```go
package main

import "net/http"
var Assets http.FileSystem 


func main() {
//Use Assets here
}
```

```go
// +build !embed

package main

import "net/http"

var Assets = http.Dir("./public")
```
Now when you build or run your project, you will have files directly served from `./public` directory.

And then to embed your resources, do

```sh
$ resources -output="public_resources.go" -var="Assets" -tag="embed" public/*
$ go build -tags=embed
```

Now your resources should be embeded with your program!
And of course, you may use any `var` name or tag you please.

### Go Generate
There is a few reasons to avoid resource embeding in Go generate,
first Go Generate is for generating Go source code from your code, generally the resources you want to embed aren't effected by the Go source directly and as such generating resources are out of the scope of Go Generate.
Second, You're unnecessarily slowing down code iterations by blocking `go generate` for resource generation.

But if you must use, put the `//go:generate resources` followed by the usual flags on the command-line somewhere in your Go files.
<commit_msg>I suck at md.<commit_after># Resources

Unfancy resources embedding with Go.

- No blings.
- No runtime dependency.
- Embeddable builder.

### Dude, Why?

Yes, there is quite a lot of projects that handles resource embeding but they come with more bling than you will probably ever need and you often ended up with having dependenies for your end project, not this time.

### Installing

Just go get it!

```sh
$ go get github.com/omeid/go-resources/cmd/resources
```


### Usage
```sh
$ resources -help
Usage of resources:
  -declare=false: Whether to declare the "var" or not.
  -output="": The filename to write the output to.
  -package="main": The name of package to generate.
  -tag="": The tag to use for the generated package. Use empty for no tag.
  -trim="": Path prefix to remove from the resulting file path
  -var="FS": The name of variable to assign the virtual-filesystem to.
```

### Optimization
Generating resources result in a very high number of lines of code, 1mb of resources result about 5mb of code at over 87 thousand lines of code, _don't worry, the size of data stored in your binary is exactly same as the resources (eg. 1mb of resources only increases your binary size by 1mb_, compiling this many lines of code takes time and slows down the compiler.
To avoid recompiling the resources every time and leverage the `go build` cache, generate your resources into a standalone package and then import it, this will allow for faster iteration as you don't have to wait for the resources to be compiled with every change.

##### "Live" development of resources 
For fast iteration and improvement of your resources, you can work around the compile with the follow technique: 

```go
package main

import "net/http"
var Assets http.FileSystem 


func main() {
//Use Assets here
}
```

```go
// +build !embed

package main

import "net/http"

var Assets = http.Dir("./public")
```
Now when you build or run your project, you will have files directly served from `./public` directory.

And then to embed your resources, do

```sh
$ resources -output="public_resources.go" -var="Assets" -tag="embed" public/*
$ go build -tags=embed
```

Now your resources should be embeded with your program!  
And of course, you may use any `var` name or tag you please.

### Go Generate
There is a few reasons to avoid resource embeding in Go generate,
first Go Generate is for generating Go source code from your code, generally the resources you want to embed aren't effected by the Go source directly and as such generating resources are out of the scope of Go Generate.
Second, You're unnecessarily slowing down code iterations by blocking `go generate` for resource generation.

But if you must use, put the `//go:generate resources` followed by the usual flags on the command-line somewhere in your Go files.

{'fraction_non_alphanumeric': 0.0728465083303793, 'fraction_numerical': 0.0021269053527118043, 'mean_word_length': 4.116047144152312, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2290277', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1446, 'n_words': 863}