func main() { port := env.StringDefault("PORT", "8000") log.SetPrefix("[lgtts] ") log.SetFlags(log.Ltime | log.Ldate | log.Lshortfile) err := lgtts.SetupPostgres() if err != nil { log.Fatal(err) } ws := lgtts.NewWebService() restful.Add(ws) log.Printf("Listening on localhost:" + port) log.Fatal(http.ListenAndServe(":"+port, nil)) }
func init() { if !flag.Parsed() { flag.Parse() } ws := &restful.WebService{} ws.Consumes(restful.MIME_JSON, "text/plain", "text/event-stream"). Produces(restful.MIME_JSON, "text/plain", "text/event-stream") log.Print("Register API to server...") registerHealthzCheckAPI(ws) restful.Add(ws) }
func main() { port := env.StringDefault("PORT", "8080") baseUrl := ":" + port var ws restful.WebService ws.Path("/api"). Consumes(restful.MIME_JSON). Produces(restful.MIME_JSON) ws.Route(ws.GET("/bar").To(getBar). Writes(Bar{})) ws.Route(ws.GET("/foo").To(getFoo). Writes(Foo{})) restful.Add(&ws) log.Printf("Starting webserver on %v...", baseUrl) log.Fatal(http.ListenAndServe(baseUrl, nil)) }
func setupTest(t *testing.T) *httptest.Server { // // Logging // log.SetPrefix("[lgtts] ") log.SetFlags(log.Lshortfile) err := SetupPostgres() if err != nil { t.Fatal(err) } dbmap.DropTables() // Ignore errors err = dbmap.CreateTables() if err != nil { t.Fatal(err) } ws := NewWebService() restful.Add(ws) hserv := httptest.NewServer(http.HandlerFunc(restful.Dispatch)) return hserv }
func main() { ws := new(restful.WebService) ws.Path("/itrain").Consumes(restful.MIME_JSON).Produces(restful.MIME_JSON) ws.Route(ws.GET("/version"). To(report_version). Doc("get itrain version number"). Operation("version")) ws.Route(ws.GET("/report_inverter"). To(report_inverter). Doc("get inverter report data"). Operation("report_inverter"). Param(ws.QueryParameter("sd", "startdate"))) restful.Add(ws) config := swagger.Config{ WebServices: restful.DefaultContainer.RegisteredWebServices(), // you control what services are visible WebServicesUrl: "/", ApiPath: "/apidocs.json", // specifiy where the UI is located SwaggerPath: "/apidocs/", SwaggerFilePath: "./swaggerui"} swagger.RegisterSwaggerService(config, restful.DefaultContainer) var ( hostname string = "127.0.0.1" port int = 8080 ) // Listen on hostname:port fmt.Printf("Listening on %s:%d...\n", hostname, port) err := http.ListenAndServe(fmt.Sprintf("%s:%d", hostname, port), nil) if err != nil { log.Fatal("Error: ", err) } }