Hi,

How I can use the .toml file to parse IP address and port to simple http 
server instead of using flags
I have a config.toml file which contains these parameters in

PORT = "8000"
Address = "localhost"


//Parameters type struct as
type Config struct {
PORT    string
Address string
}

I can load file in main function as

var conf Config
if _, err := toml.Decode("config.toml", &conf); err != nil {
// handle error
}


//simple http server main function

func main() {
var dir string

flag.StringVar(&dir, "dir", ".", "the directory to serve files from. 
Defaults to the current dir")
flag.Parse()
r := mux.NewRouter()

// This will serve files under http://localhost:8000/static/<filename>
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", 
http.FileServer(http.Dir(dir))))

srv := &http.Server{
Handler:      r,
Addr:         "127.0.0.1:8000",
WriteTimeout: 15 * time.Second,
ReadTimeout:  15 * time.Second,
}

log.Fatal(srv.ListenAndServe())
}

Any help?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f095834a-5bde-4ae2-93dd-5f2f39212aa2%40googlegroups.com.

Reply via email to