1 Star 0 Fork 0

jerryduren / architecture

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
openapi_server.gen.go 5.66 KB
一键复制 编辑 原始数据 按行查看 历史
jerryduren 提交于 2021-10-07 23:17 . a
// Package ports provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version (devel) DO NOT EDIT.
package main
import (
"context"
"fmt"
"gitee.com/jerryduren/architecture/go-with-domain/demo5gc/internal/smf/domain"
"github.com/go-chi/chi"
"net/http"
"github.com/deepmap/oapi-codegen/pkg/runtime"
)
// ServerInterface represents all server handlers.
type ServerInterface interface {
// Create SM Context
// (POST /sm-contexts)
PostSmContexts(w http.ResponseWriter, r *http.Request)
// Update SM Context
// (POST /sm-contexts/{smContextRef}/modify)
UpdateSmContext(w http.ResponseWriter, r *http.Request, smContextRef string)
// Release SM Context
// (POST /sm-contexts/{smContextRef}/release)
ReleaseSmContext(w http.ResponseWriter, r *http.Request, smContextRef string)
// Retrieve SM Context
// (POST /sm-contexts/{smContextRef}/retrieve)
RetrieveSmContext(w http.ResponseWriter, r *http.Request, smContextRef string)
}
// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
Handler ServerInterface
HandlerMiddlewares []MiddlewareFunc
}
type MiddlewareFunc func(http.HandlerFunc) http.HandlerFunc
// PostSmContexts operation middleware
func (siw *ServerInterfaceWrapper) PostSmContexts(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
ctx = context.WithValue(ctx, domain.OAuth2ClientCredentialsScopes, []string{"nsmf-pdusession"})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.PostSmContexts(w, r)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// UpdateSmContext operation middleware
func (siw *ServerInterfaceWrapper) UpdateSmContext(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "smContextRef" -------------
var smContextRef string
err = runtime.BindStyledParameter("simple", false, "smContextRef", chi.URLParam(r, "smContextRef"), &smContextRef)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter smContextRef: %s", err), http.StatusBadRequest)
return
}
ctx = context.WithValue(ctx, domain.OAuth2ClientCredentialsScopes, []string{"nsmf-pdusession"})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.UpdateSmContext(w, r, smContextRef)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// ReleaseSmContext operation middleware
func (siw *ServerInterfaceWrapper) ReleaseSmContext(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "smContextRef" -------------
var smContextRef string
err = runtime.BindStyledParameter("simple", false, "smContextRef", chi.URLParam(r, "smContextRef"), &smContextRef)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter smContextRef: %s", err), http.StatusBadRequest)
return
}
ctx = context.WithValue(ctx, domain.OAuth2ClientCredentialsScopes, []string{"nsmf-pdusession"})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ReleaseSmContext(w, r, smContextRef)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// RetrieveSmContext operation middleware
func (siw *ServerInterfaceWrapper) RetrieveSmContext(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var err error
// ------------- Path parameter "smContextRef" -------------
var smContextRef string
err = runtime.BindStyledParameter("simple", false, "smContextRef", chi.URLParam(r, "smContextRef"), &smContextRef)
if err != nil {
http.Error(w, fmt.Sprintf("Invalid format for parameter smContextRef: %s", err), http.StatusBadRequest)
return
}
ctx = context.WithValue(ctx, domain.OAuth2ClientCredentialsScopes, []string{"nsmf-pdusession"})
var handler = func(w http.ResponseWriter, r *http.Request) {
siw.Handler.RetrieveSmContext(w, r, smContextRef)
}
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler(w, r.WithContext(ctx))
}
// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{})
}
type ChiServerOptions struct {
BaseURL string
BaseRouter chi.Router
Middlewares []MiddlewareFunc
}
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{
BaseRouter: r,
})
}
func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler {
return HandlerWithOptions(si, ChiServerOptions{
BaseURL: baseURL,
BaseRouter: r,
})
}
// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler {
r := options.BaseRouter
if r == nil {
r = chi.NewRouter()
}
wrapper := ServerInterfaceWrapper{
Handler: si,
HandlerMiddlewares: options.Middlewares,
}
r.Group(func(r chi.Router) {
r.Post(options.BaseURL+"/sm-contexts", wrapper.PostSmContexts)
})
r.Group(func(r chi.Router) {
r.Post(options.BaseURL+"/sm-contexts/{smContextRef}/modify", wrapper.UpdateSmContext)
})
r.Group(func(r chi.Router) {
r.Post(options.BaseURL+"/sm-contexts/{smContextRef}/release", wrapper.ReleaseSmContext)
})
r.Group(func(r chi.Router) {
r.Post(options.BaseURL+"/sm-contexts/{smContextRef}/retrieve", wrapper.RetrieveSmContext)
})
return r
}
Go
1
https://gitee.com/jerryduren/architecture.git
git@gitee.com:jerryduren/architecture.git
jerryduren
architecture
architecture
36a2cef21a1f

搜索帮助