For this I created nrsc, it's a resource compiler that will compile your resources to a local nrsc package which you can include in your project. Building your project after running nrsc will embed all the resource in the executable.
To install nrsc just run go get bitbucket.org/tebeka/nrsc
Here's an example on how to use nrsc in your code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/http" | |
"os" | |
"./nrsc" | |
) | |
func indexHandler(w http.ResponseWriter, req *http.Request) { | |
fmt.Fprintf(w, "Hello World\n") | |
} | |
func main() { | |
nrsc.Handle("/static/") | |
http.HandleFunc("/", indexHandler) | |
if err := http.ListenAndServe(":8080", nil); err != nil { | |
fmt.Fprintf(os.Stderr, "error: %s\n", err) | |
os.Exit(1) | |
} | |
} |
No comments:
Post a Comment