func (suite *TestSuiteConf) SetUpSuite(c *C) { suite.stop, suite.stopped = server.NewService(). ListenPort(suite.port). WithAuth(server.Auth{VerifyKeyFunc: testutil.PublicKeyFunc}.Init()). Route(server.Endpoint{UrlRoute: "/template1", HttpMethod: server.GET, AuthScope: server.AuthScope("secure")}). To(func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { resp.Write([]byte(suite.template1)) c.Log("/template1 called") }). Route(server.Endpoint{UrlRoute: "/template2", HttpMethod: server.GET, AuthScope: server.AuthScope("secure")}). To(func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { resp.Write([]byte(suite.template2)) c.Log("/template2 called") }). Start() }
func startServer(port int) <-chan error { reverseProxy := func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { hostPort := server.GetUrlParameter(req, "host_port") server.NewReverseProxy().SetForwardHostPort(hostPort).Strip("/"+hostPort).ServeHTTP(resp, req) } key := loadPublicKeyFromFile() _, stopped := server.NewService(). WithAuth( server.Auth{ VerifyKeyFunc: func() []byte { return key }, }.Init()). ListenPort(port). Route( server.Endpoint{ UrlRoute: "/{host_port}/{url:.*}", HttpMethods: []server.HttpMethod{server.GET, server.POST, server.PUT, server.PATCH, server.DELETE}, AuthScope: server.AuthScopeNone, }). To(reverseProxy). Route( server.Endpoint{ UrlRoute: "/secure/{host_port}/{url:.*}", HttpMethods: []server.HttpMethod{server.GET, server.POST, server.PUT, server.PATCH, server.DELETE}, AuthScope: server.AuthScope("secure"), }). To(reverseProxy). Start() return stopped }
func (suite *TestSuiteFuncs) SetUpSuite(c *C) { suite.stop, suite.stopped = server.NewService(). ListenPort(suite.port). WithAuth(server.Auth{VerifyKeyFunc: testutil.PublicKeyFunc}.Init()). Route(server.Endpoint{UrlRoute: "/content", HttpMethod: server.GET, AuthScope: server.AuthScopeNone}). To(func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { resp.Write([]byte(suite.content)) }). Route(server.Endpoint{UrlRoute: "/secure", HttpMethod: server.GET, AuthScope: server.AuthScope("secure")}). To(func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { resp.Write([]byte(suite.content)) }).Start() suite.contentFile = os.TempDir() + "/test-content" err := ioutil.WriteFile(suite.contentFile, []byte(contentFileContent), 0644) c.Assert(err, IsNil) }
func startServer(port int) <-chan error { key := loadPublicKeyFromFile() // For implementing shutdown proxy := make(chan bool) stop, stopped := server.NewService(). WithAuth( server.Auth{ VerifyKeyFunc: func() []byte { return key }, }.Init()). ListenPort(port). Route( server.Endpoint{ UrlRoute: "/info", HttpMethod: server.GET, AuthScope: server.AuthScopeNone, }). To( func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { glog.Infoln("Showing version info.") server.Marshal(resp, req, version.BuildInfo()) }). Route( server.Endpoint{ UrlRoute: "/quitquitquit", HttpMethod: server.POST, AuthScope: server.AuthScope("quitquitquit"), }). To( func(ctx context.Context, resp http.ResponseWriter, req *http.Request) { glog.Infoln("Stopping the server....") proxy <- true }). OnShutdown( func() error { glog.Infoln("Executing user custom shutdown...") return nil }). Start() // For stopping the server go func() { <-proxy stop <- 1 }() return stopped }