func main() { cpath := flag.String("c", "config.ini", "Sets the configuration .ini file used.") flag.Parse() // CLI arguments conf := config.ReadConfig(*cpath) mem := flag.Uint64("m", conf.Server.Memory, "Sets the maximum memory to be used for caching images in bytes. Does not account for memory consumption of other things.") imagick.Initialize() defer imagick.Terminate() log.Println("Server starting...") logging.Debug("Debug enabled") server, handler, ln := NewServer(8005, *mem, conf) handler.started = time.Now() err := server.Serve(ln) end := time.Now() // Get number of requests requests := strconv.FormatUint((*handler).requests, 10) // Calculate the elapsed time duration := end.Sub(handler.started) log.Println("Server requests: " + requests) log.Println("Server uptime: " + duration.String()) // Log errors if err != nil { log.Fatal(err) } }
// This is an utility function to launch a server. func startServer() (server *fasthttp.Server, ln net.Listener, srverr chan error) { // Start the server conf := config.ReadConfig("config/testconfig.ini") port++ server, _, ln = NewServer(port, 500000, conf) srverr = make(chan error) go func() { srverr <- server.Serve(ln) }() time.Sleep(100 * time.Millisecond) return }