func main() { app := webshell.NewApp("webshell tutorial", "", server_port) app.AddRoute("/", servePage) app.StaticRoute("/assets/", "assets/") app.StaticRoute("/examples/", "examples/") fmt.Println("[!] ", app.Serve()) }
func main() { // load the requisite environment variables app := webshell.NewApp("webshell basic example", "127.0.0.1", "8080") // add an endpoint to our server app.AddRoute("/", hello_world) // start a HTTP-only web server app.Serve() }
func main() { // load the requisite environment variables app := webshell.NewApp("webshell basic example", "127.0.0.1", "8080") // set up our static routes app.StaticRoute("/assets/css/", "assets/css/") app.StaticRoute("/", "static") // start a HTTP-only web server app.Serve() }
func main() { // load the requisite environment variables app := webshell.NewApp("basic asset cache", "", "8080") // create the asset cache assetcache.BackgroundAttachAssetCache(app, "/assets/", "assets/") app.StaticRoute("/", "static") // start a HTTP-only web server log.Fatal(app.Serve()) }
func main() { port := os.Getenv("PORT") if port == "" { port = "8080" } app := webshell.NewApp("multipart form example", "127.0.0.1", port) app.AddRoute("/", home) app.StaticRoute("/images/", "images/") app.Serve() }
func main() { // load the requisite environment variables app := webshell.NewApp("webshell basic example", "127.0.0.1", "8080") // add an endpoint to our server app.AddRoute("/", index) app.AddRoute("/test.html", tpl_test) app.AddRoute("/test2.html", tpl_test2) app.AddRoute("/error.html", tpl_error) // start a HTTP-only web server app.Serve() }
func main() { // load the requisite environment variables app := webshell.NewApp("basic asset cache", "", "8080") // create the asset cache, caching 4 files up to 4MB assetcache.MaxItems = 4 assetcache.MaxSize = 4194304 ac := assetcache.CreateAssetCache("/assets/", "assets/") if err := ac.Start(); err != nil { panic("could not start asset cache: " + err.Error()) } app.AddRoute("/assets/", assetcache.AssetHandler(ac)) app.StaticRoute("/", "static") // start a HTTP-only web server log.Fatal(app.Serve()) }
func initServer(serverCfg map[string]string) { var ( address = "127.0.0.1" port = "8080" ) for key, val := range serverCfg { switch key { case "port": port = val case "address": address = val } } if Security.TLS.Enabled { app = webshell.NewTLSApp("gowik", address, port, Security.TLS.Key, Security.TLS.Cert) } else { app = webshell.NewApp("gowik", address, port) } }
func main() { var host, port string conf, err := config.ParseFile(config_file) if err != nil { fmt.Printf("[!] couldn't parse config file: %s\n", err.Error()) os.Exit(1) } if conf["server"] == nil { host = DEFAULT_HOST port = DEFAULT_PORT } else { if conf["server"]["port"] != "" { port = conf["server"]["port"] } else { port = DEFAULT_PORT } if conf["server"]["host"] != "" { host = conf["server"]["host"] } else { port = DEFAULT_HOST } if conf["server"]["development"] == "false" { server_dev = false server_secure = true } if conf["server"]["dbfile"] != "" { dbFile = conf["server"]["dbfile"] } if conf["server"]["authenticate"] == "false" { check_auth = false } else { init_auth() } if conf["server"]["admin_user"] != "" { admin_user = conf["server"]["admin_user"] ok, err := userExists(admin_user) if err != nil { panic(err) } else if !ok { panic("User does not exists.") } } if conf["server"]["access_log"] != "" { access_logfile = conf["server"]["access_log"] } error_logfile = access_logfile if conf["server"]["error_log"] != "" { error_logfile = conf["server"]["error_log"] } } if conf["page"] == nil { page_title = DEFAULT_TITLE server_host = "localhost" } else { if conf["page"]["title"] != "" { page_title = conf["page"]["title"] } else { page_title = DEFAULT_TITLE } if conf["page"]["host"] != "" { server_host = conf["page"]["title"] } else { server_host = "localhost" } } if server_dev { server_host = fmt.Sprintf("%s:%s", server_host, port) } NotFound, err = webshell.GenerateTemplateErrorHandler(http.StatusNotFound, "templates/404.html") if err != nil { panic(err.Error()) } app := webshell.NewApp("urlshorten-ng", host, port) err = assetcache.BackgroundAttachAssetCache(app, "/assets/", "assets/") if err != nil { log.Fatal("[!] ", err.Error()) } app.AddConditionalRoute(check_auth, "/add", addUser) app.AddConditionalRoute(check_auth, "/change", changePass) app.AddRoute("/views/", getViews) app.AddRoute("/", topRoute) log.Printf("[+] listening on %s:%s\n", host, port) log.Fatal(app.Serve()) }