本文整理匯總了Golang中github.com/emicklei/go-restful.NewContainer函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewContainer函數的具體用法?Golang NewContainer怎麽用?Golang NewContainer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewContainer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: setupHandlers
func setupHandlers(metricSink *metricsink.MetricSink, podLister *cache.StoreToPodLister) http.Handler {
runningInKubernetes := true
// Make API handler.
wsContainer := restful.NewContainer()
wsContainer.EnableContentEncoding(true)
wsContainer.Router(restful.CurlyRouter{})
a := v1.NewApi(runningInKubernetes, metricSink)
a.Register(wsContainer)
// Metrics API
m := metricsApi.NewApi(metricSink, podLister)
m.Register(wsContainer)
handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
switch name {
case "profile":
pprof.Profile(resp, req.Request)
case "symbol":
pprof.Symbol(resp, req.Request)
case "cmdline":
pprof.Cmdline(resp, req.Request)
default:
pprof.Index(resp, req.Request)
}
}
// Setup pporf handlers.
ws := new(restful.WebService).Path(pprofBasePath)
ws.Route(ws.GET("/{subpath:*}").To(metrics.InstrumentRouteFunc("pprof", handlePprofEndpoint))).Doc("pprof endpoint")
wsContainer.Add(ws)
return wsContainer
}
示例2: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client) http.Handler {
apiHandler := ApiHandler{client}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Path("/api/deploy").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeployment{}).
Writes(AppDeployment{}))
wsContainer.Add(deployWs)
microserviceListWs := new(restful.WebService)
microserviceListWs.Path("/api/microservice").
Produces(restful.MIME_JSON)
microserviceListWs.Route(
microserviceListWs.GET("").
To(apiHandler.handleGetMicroserviceList).
Writes(MicroserviceList{}))
wsContainer.Add(microserviceListWs)
return wsContainer
}
示例3: NewServer
// TODO(timstclair): Add auth(n/z) interface & handling.
func NewServer(config Config, runtime Runtime) (Server, error) {
s := &server{
config: config,
runtime: &criAdapter{runtime},
}
ws := &restful.WebService{}
endpoints := []struct {
path string
handler restful.RouteFunction
}{
{"/exec/{containerID}", s.serveExec},
{"/attach/{containerID}", s.serveAttach},
{"/portforward/{podSandboxID}", s.servePortForward},
}
for _, e := range endpoints {
for _, method := range []string{"GET", "POST"} {
ws.Route(ws.
Method(method).
Path(e.path).
To(e.handler))
}
}
handler := restful.NewContainer()
handler.Add(ws)
s.handler = handler
return s, nil
}
示例4: CreateApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateApiHandler(client *client.Client) http.Handler {
wsContainer := restful.NewContainer()
// TODO(bryk): This is for tests only. Replace with real implementation once ready.
ws := new(restful.WebService)
ws.Path("/api/deploy").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
ws.Route(ws.POST("").To(func(request *restful.Request, response *restful.Response) {
cfg := new(DeployAppConfig)
if err := request.ReadEntity(cfg); err != nil {
HandleInternalError(response, err)
return
}
if err := DeployApp(cfg, client); err != nil {
HandleInternalError(response, err)
return
}
response.WriteHeaderAndEntity(http.StatusCreated, cfg)
}).Reads(DeployAppConfig{}).Writes(DeployAppConfig{}))
wsContainer.Add(ws)
return wsContainer
}
示例5: runRestfulMsgPackRouterServer
func runRestfulMsgPackRouterServer() {
container := restful.NewContainer()
register(container)
log.Printf("start listening on localhost:8090")
server := &http.Server{Addr: ":8090", Handler: container}
log.Fatal(server.ListenAndServe())
}
示例6: NewServer
// NewServer initializes and configures a kubelet.Server object to handle HTTP requests.
func NewServer(host HostInterface, enableDebuggingHandlers bool) Server {
server := Server{
host: host,
restfulCont: restful.NewContainer(),
}
server.InstallDefaultHandlers()
if enableDebuggingHandlers {
server.InstallDebuggingHandlers()
}
return server
}
示例7: setupHandlers
func setupHandlers(sources []api.Source, sink sinks.ExternalSinkManager, m manager.Manager) http.Handler {
// Make API handler.
wsContainer := restful.NewContainer()
a := v1.NewApi(m)
a.Register(wsContainer)
// Validation/Debug handler.
handleValidate := func(req *restful.Request, resp *restful.Response) {
err := validate.HandleRequest(resp, sources, sink)
if err != nil {
fmt.Fprintf(resp, "%s", err)
}
}
ws := new(restful.WebService).
Path("/validate").
Produces("text/plain")
ws.Route(ws.GET("").To(handleValidate)).
Doc("get validation information")
wsContainer.Add(ws)
// TODO(jnagal): Add a main status page.
// Redirect root to /validate
redirectHandler := http.RedirectHandler(validate.ValidatePage, http.StatusTemporaryRedirect)
handleRoot := func(req *restful.Request, resp *restful.Response) {
redirectHandler.ServeHTTP(resp, req.Request)
}
ws = new(restful.WebService)
ws.Route(ws.GET("/").To(handleRoot))
wsContainer.Add(ws)
handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
switch name {
case "profile":
pprof.Profile(resp, req.Request)
case "symbol":
pprof.Symbol(resp, req.Request)
case "cmdline":
pprof.Cmdline(resp, req.Request)
default:
pprof.Index(resp, req.Request)
}
}
// Setup pporf handlers.
ws = new(restful.WebService).Path(pprofBasePath)
ws.Route(ws.GET("/{subpath:*}").To(func(req *restful.Request, resp *restful.Response) {
handlePprofEndpoint(req, resp)
})).Doc("pprof endpoint")
wsContainer.Add(ws)
return wsContainer
}
示例8: NewServer
// NewServer initializes and configures a kubelet.Server object to handle HTTP requests.
func NewServer(host HostInterface, auth AuthInterface, enableDebuggingHandlers bool) Server {
server := Server{
host: host,
auth: auth,
restfulCont: &filteringContainer{Container: restful.NewContainer()},
}
if auth != nil {
server.InstallAuthFilter()
}
server.InstallDefaultHandlers()
if enableDebuggingHandlers {
server.InstallDebuggingHandlers()
}
return server
}
示例9: TestServiceWrapper
func TestServiceWrapper(t *testing.T) {
backend := expander.NewExpander("../expansion/expansion.py")
wrapper := NewService(NewExpansionHandler(backend))
container := restful.NewContainer()
container.ServeMux = http.NewServeMux()
wrapper.Register(container)
handlerTester := util.NewHandlerTester(container)
for _, swtc := range ServiceWrapperTestCases {
reader := GetTemplateReader(t, swtc.Description, inputFileName)
w, err := handlerTester(swtc.HTTPMethod, swtc.ServiceURLPath, swtc.ContentType, reader)
if err != nil {
t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
}
if w.Code != http.StatusOK {
if w.Code != swtc.StatusCode {
message := fmt.Sprintf("test returned code:%d, status: %s", w.Code, w.Body.String())
t.Errorf("error in test case '%s': %s\n", swtc.Description, message)
}
} else {
if swtc.StatusCode != http.StatusOK {
t.Errorf("expected error did not occur in test case '%s': want: %d have: %d\n",
swtc.Description, swtc.StatusCode, w.Code)
}
body := w.Body.Bytes()
actualResponse := &expander.ExpansionResponse{}
if err := json.Unmarshal(body, actualResponse); err != nil {
t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
}
actualResult, err := actualResponse.Unmarshal()
if err != nil {
t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
}
expectedOutput := GetOutputString(t, swtc.Description)
expectedResult := expandOutputOrDie(t, expectedOutput, swtc.Description)
if !reflect.DeepEqual(expectedResult, actualResult) {
message := fmt.Sprintf("want: %s\nhave: %s\n",
util.ToYAMLOrError(expectedResult), util.ToYAMLOrError(actualResult))
t.Errorf("error in test case '%s':\n%s\n", swtc.Description, message)
}
}
}
}
示例10: NewServer
// TODO(timstclair): Add auth(n/z) interface & handling.
func NewServer(config Config, runtime Runtime) (Server, error) {
s := &server{
config: config,
runtime: &criAdapter{runtime},
cache: newRequestCache(),
}
if s.config.BaseURL == nil {
s.config.BaseURL = &url.URL{
Scheme: "http",
Host: s.config.Addr,
}
if s.config.TLSConfig != nil {
s.config.BaseURL.Scheme = "https"
}
}
ws := &restful.WebService{}
endpoints := []struct {
path string
handler restful.RouteFunction
}{
{"/exec/{token}", s.serveExec},
{"/attach/{token}", s.serveAttach},
{"/portforward/{token}", s.servePortForward},
}
// If serving relative to a base path, set that here.
pathPrefix := path.Dir(s.config.BaseURL.Path)
for _, e := range endpoints {
for _, method := range []string{"GET", "POST"} {
ws.Route(ws.
Method(method).
Path(path.Join(pathPrefix, e.path)).
To(e.handler))
}
}
handler := restful.NewContainer()
handler.Add(ws)
s.handler = handler
return s, nil
}
示例11: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client) http.Handler {
apiHandler := ApiHandler{client}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Path("/api/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeployment{}).
Writes(AppDeployment{}))
wsContainer.Add(deployWs)
replicaSetWs := new(restful.WebService)
replicaSetWs.Path("/api/replicasets").
Produces(restful.MIME_JSON)
replicaSetWs.Route(
replicaSetWs.GET("").
To(apiHandler.handleGetReplicaSetList).
Writes(ReplicaSetList{}))
replicaSetWs.Route(
replicaSetWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(ReplicaSetDetail{}))
wsContainer.Add(replicaSetWs)
namespaceListWs := new(restful.WebService)
namespaceListWs.Path("/api/namespaces").
Produces(restful.MIME_JSON)
namespaceListWs.Route(
namespaceListWs.GET("").
To(apiHandler.handleGetNamespaceList).
Writes(NamespacesList{}))
wsContainer.Add(namespaceListWs)
return wsContainer
}
示例12: NewServer
// NewServer initializes and configures a kubelet.Server object to handle HTTP requests.
func NewServer(
host HostInterface,
resourceAnalyzer stats.ResourceAnalyzer,
auth AuthInterface,
enableDebuggingHandlers bool,
runtime kubecontainer.Runtime) Server {
server := Server{
host: host,
resourceAnalyzer: resourceAnalyzer,
auth: auth,
restfulCont: &filteringContainer{Container: restful.NewContainer()},
runtime: runtime,
}
if auth != nil {
server.InstallAuthFilter()
}
server.InstallDefaultHandlers()
if enableDebuggingHandlers {
server.InstallDebuggingHandlers()
}
return server
}
示例13: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
clientConfig clientcmd.ClientConfig) http.Handler {
apiHandler := ApiHandler{client, heapsterClient, clientConfig}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Filter(wsLogger)
deployWs.Path("/api/v1/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
deployWs.Route(
deployWs.POST("/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
deployWs.Route(
deployWs.POST("/validate/protocol").
To(apiHandler.handleProtocolValidity).
Reads(ProtocolValiditySpec{}).
Writes(ProtocolValidity{}))
deployWs.Route(
deployWs.GET("/protocols").
To(apiHandler.handleGetAvailableProcotols).
Writes(Protocols{}))
wsContainer.Add(deployWs)
deployFromFileWs := new(restful.WebService)
deployFromFileWs.Path("/api/v1/appdeploymentfromfile").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployFromFileWs.Route(
deployFromFileWs.POST("").
To(apiHandler.handleDeployFromFile).
Reads(AppDeploymentFromFileSpec{}).
Writes(AppDeploymentFromFileResponse{}))
wsContainer.Add(deployFromFileWs)
replicationControllerWs := new(restful.WebService)
replicationControllerWs.Filter(wsLogger)
replicationControllerWs.Path("/api/v1/replicationcontrollers").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
replicationControllerWs.Route(
replicationControllerWs.GET("").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
replicationControllerWs.Route(
replicationControllerWs.GET("/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerDetail).
Writes(ReplicationControllerDetail{}))
replicationControllerWs.Route(
replicationControllerWs.POST("/{namespace}/{replicationController}/update/pods").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicationControllerSpec{}))
replicationControllerWs.Route(
replicationControllerWs.DELETE("/{namespace}/{replicationController}").
To(apiHandler.handleDeleteReplicationController))
replicationControllerWs.Route(
replicationControllerWs.GET("/pods/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerPods).
Writes(ReplicationControllerPods{}))
wsContainer.Add(replicationControllerWs)
namespacesWs := new(restful.WebService)
namespacesWs.Filter(wsLogger)
namespacesWs.Path("/api/v1/namespaces").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
namespacesWs.Route(
namespacesWs.POST("").
To(apiHandler.handleCreateNamespace).
Reads(NamespaceSpec{}).
Writes(NamespaceSpec{}))
namespacesWs.Route(
namespacesWs.GET("").
To(apiHandler.handleGetNamespaces).
Writes(NamespaceList{}))
wsContainer.Add(namespacesWs)
logsWs := new(restful.WebService)
logsWs.Filter(wsLogger)
logsWs.Path("/api/v1/logs").
Produces(restful.MIME_JSON)
logsWs.Route(
logsWs.GET("/{namespace}/{podId}").
To(apiHandler.handleLogs).
Writes(Logs{}))
logsWs.Route(
logsWs.GET("/{namespace}/{podId}/{container}").
To(apiHandler.handleLogs).
Writes(Logs{}))
wsContainer.Add(logsWs)
//.........這裏部分代碼省略.........
示例14: CreateHttpApiHandler
// CreateHttpApiHandler creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client, heapsterClient HeapsterClient,
clientConfig clientcmd.ClientConfig) http.Handler {
verber := common.NewResourceVerber(client.RESTClient, client.ExtensionsClient.RESTClient,
client.AppsClient.RESTClient, client.BatchClient.RESTClient)
apiHandler := ApiHandler{client, heapsterClient, clientConfig, verber}
wsContainer := restful.NewContainer()
apiV1Ws := new(restful.WebService)
apiV1Ws.Filter(wsLogger)
apiV1Ws.Path("/api/v1").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
wsContainer.Add(apiV1Ws)
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/imagereference").
To(apiHandler.handleImageReferenceValidity).
Reads(ImageReferenceValiditySpec{}).
Writes(ImageReferenceValidity{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeployment/validate/protocol").
To(apiHandler.handleProtocolValidity).
Reads(ProtocolValiditySpec{}).
Writes(ProtocolValidity{}))
apiV1Ws.Route(
apiV1Ws.GET("/appdeployment/protocols").
To(apiHandler.handleGetAvailableProcotols).
Writes(Protocols{}))
apiV1Ws.Route(
apiV1Ws.POST("/appdeploymentfromfile").
To(apiHandler.handleDeployFromFile).
Reads(AppDeploymentFromFileSpec{}).
Writes(AppDeploymentFromFileResponse{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/{namespace}").
To(apiHandler.handleGetReplicationControllerList).
Writes(ReplicationControllerList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerDetail).
Writes(ReplicationControllerDetail{}))
apiV1Ws.Route(
apiV1Ws.POST("/replicationcontroller/{namespace}/{replicationController}/update/pod").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicationControllerSpec{}))
apiV1Ws.Route(
apiV1Ws.DELETE("/replicationcontroller/{namespace}/{replicationController}").
To(apiHandler.handleDeleteReplicationController))
apiV1Ws.Route(
apiV1Ws.GET("/replicationcontroller/pod/{namespace}/{replicationController}").
To(apiHandler.handleGetReplicationControllerPods).
Writes(ReplicationControllerPods{}))
apiV1Ws.Route(
apiV1Ws.GET("/workload").
To(apiHandler.handleGetWorkloads).
Writes(workload.Workloads{}))
apiV1Ws.Route(
apiV1Ws.GET("/workload/{namespace}").
To(apiHandler.handleGetWorkloads).
Writes(workload.Workloads{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset").
To(apiHandler.handleGetReplicaSets).
Writes(replicaset.ReplicaSetList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset/{namespace}").
To(apiHandler.handleGetReplicaSets).
Writes(replicaset.ReplicaSetList{}))
apiV1Ws.Route(
apiV1Ws.GET("/replicaset/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(replicaset.ReplicaSetDetail{}))
apiV1Ws.Route(
apiV1Ws.GET("/pod").
To(apiHandler.handleGetPods).
Writes(pod.PodList{}))
apiV1Ws.Route(
apiV1Ws.GET("/pod/{namespace}").
To(apiHandler.handleGetPods).
//.........這裏部分代碼省略.........
示例15: CreateHttpApiHandler
// Creates a new HTTP handler that handles all requests to the API of the backend.
func CreateHttpApiHandler(client *client.Client) http.Handler {
apiHandler := ApiHandler{client}
wsContainer := restful.NewContainer()
deployWs := new(restful.WebService)
deployWs.Path("/api/appdeployments").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
deployWs.Route(
deployWs.POST("").
To(apiHandler.handleDeploy).
Reads(AppDeploymentSpec{}).
Writes(AppDeploymentSpec{}))
deployWs.Route(
deployWs.POST("/validate/name").
To(apiHandler.handleNameValidity).
Reads(AppNameValiditySpec{}).
Writes(AppNameValidity{}))
wsContainer.Add(deployWs)
replicaSetWs := new(restful.WebService)
replicaSetWs.Path("/api/replicasets").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
replicaSetWs.Route(
replicaSetWs.GET("").
To(apiHandler.handleGetReplicaSetList).
Writes(ReplicaSetList{}))
replicaSetWs.Route(
replicaSetWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetDetail).
Writes(ReplicaSetDetail{}))
replicaSetWs.Route(
replicaSetWs.POST("/{namespace}/{replicaSet}/update/pods").
To(apiHandler.handleUpdateReplicasCount).
Reads(ReplicaSetSpec{}))
replicaSetWs.Route(
replicaSetWs.DELETE("/{namespace}/{replicaSet}").
To(apiHandler.handleDeleteReplicaSet))
replicaSetWs.Route(
replicaSetWs.GET("/pods/{namespace}/{replicaSet}").
To(apiHandler.handleGetReplicaSetPods).
Writes(ReplicaSetPods{}))
wsContainer.Add(replicaSetWs)
namespacesWs := new(restful.WebService)
namespacesWs.Path("/api/namespaces").
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)
namespacesWs.Route(
namespacesWs.POST("").
To(apiHandler.handleCreateNamespace).
Reads(NamespaceSpec{}).
Writes(NamespaceSpec{}))
namespacesWs.Route(
namespacesWs.GET("").
To(apiHandler.handleGetNamespaces).
Writes(NamespaceList{}))
wsContainer.Add(namespacesWs)
logsWs := new(restful.WebService)
logsWs.Path("/api/logs").
Produces(restful.MIME_JSON)
logsWs.Route(
logsWs.GET("/{namespace}/{podId}/{container}").
To(apiHandler.handleLogs).
Writes(Logs{}))
wsContainer.Add(logsWs)
eventsWs := new(restful.WebService)
eventsWs.Path("/api/events").
Produces(restful.MIME_JSON)
eventsWs.Route(
eventsWs.GET("/{namespace}/{replicaSet}").
To(apiHandler.handleEvents).
Writes(Events{}))
wsContainer.Add(eventsWs)
return wsContainer
}