Documentation
¶
Overview ¶
Package server turns the operations of the Go model into a server: the service contract a service implements, the HTTP adapter that calls it, the router of one framework, and the scaffold files a project starts from.
Index ¶
- Constants
- func Blocks() []string
- func Frameworks() map[string]framework.Framework
- func Templates(fw framework.Framework) []render.Set
- type AdapterView
- type BodyView
- type CheckView
- type Constructor
- type ConstructorView
- type ErrorsView
- type FieldView
- type Generator
- type GroupView
- type HandlerView
- type HeadersView
- type ObjectView
- type OperationView
- type Options
- type ParamView
- type PresenceView
- type PropView
- type RejectCaseView
- type RejectView
- type RouteView
- type RouterView
- type Scaffold
- type ScaffoldMainView
- type ScaffoldMiddlewareView
- type ScaffoldOperationView
- type ScaffoldServiceView
- type ServiceView
- type TypedErrorView
Constants ¶
const ( PartService layout.PartID = "server.service" PartErrors layout.PartID = "server.errors" PartAdapter layout.PartID = "server.adapter" PartRouter layout.PartID = "server.router" )
The server parts. The scaffold parts are layout's, since the layout places them.
const (
BlockRouterExtra = "server.router-extra"
)
The blocks of the server templates a config may override.
Variables ¶
This section is empty.
Functions ¶
func Blocks ¶
func Blocks() []string
Blocks lists the blocks of the server templates a config may override, whatever the framework.
func Frameworks ¶
Frameworks lists the frameworks a router can be generated for, by name.
Types ¶
type AdapterView ¶
type AdapterView struct {
Service string
Runtime string
HTTPServer string
Validation string
HTTP string
JSON string
Errors string
MaxMemory int64
IsRequestValidated bool
IsResponseValidated bool
Handler framework.Handler
Operations []HandlerView
Presence *PresenceView
Rejects []RejectView
}
AdapterView is the data of the adapter part. Service is the interface, as the file writes it; Handler is the shape of the handlers the framework takes. Presence is the table the handlers check bodies against, nil when none does. Rejects are the error types of the spec that answer the requests the handlers turn away.
type BodyView ¶
type BodyView struct {
Kind string
MediaType string
Case string
Runtime string
OperationID string
IsJSON bool
IsForm bool
IsMultipart bool
IsText bool
IsValue bool
IsBytes bool
IsFile bool
IsRequired bool
Field string
Target string
Type string
Assign string
Check *PropView
Encoding string
EncodingLiteral string
}
BodyView is one media type of the request body. MediaType is quoted, in lower case and without parameters; Case is the case of the body switch that takes it; OperationID is quoted; Target is the address of the options field; Type is the struct a multipart form fills; Assign is the expression that turns text, data or file, the decoded body, into the field's type. Check is what the body is checked against before it is decoded, nil when it is not. Encoding is nil or the variable encoding, which EncodingLiteral sets.
type CheckView ¶
CheckView validates the Field of the options under Path, a quoted name, when it is set.
type Constructor ¶
type Constructor struct {
Name string
HasStatusArg bool
Body gomodel.Content
HasBody bool
IsStream bool
}
Constructor is one function that makes the response data of a status.
func Constructors ¶
Constructors lists the constructors of r: one for its body read whole, one for its frames.
type ConstructorView ¶
type ConstructorView struct {
Name string
Doc string
Status string
HasStatusArg bool
Arg string
Body string
ContentType string
}
ConstructorView is one response constructor; Status is a literal or the status argument.
type ErrorsView ¶
type ErrorsView struct {
HTTPServer string
}
ErrorsView is the data of the errors part: the runtime types it names.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator builds the template data of every server part.
func (*Generator) Needs ¶
Needs names, for each block of a scaffold the config does not write, the key it has to set.
type GroupView ¶
GroupView is the parameters of one location: the options field that holds them, its struct type, and how each is decoded.
type HandlerView ¶
type HandlerView struct {
Name string
ID string
Serve string
ServeSignature string
Context string
Method string
Path string
Options string
HasQuery bool
Groups []GroupView
QueryString *ParamView
HasBody bool
Tag string
Empty string
Bodies []BodyView
Patterns []BodyView
Wildcards []BodyView
IsBodyRequired bool
Errors []TypedErrorView
}
HandlerView is one handler method. ID is the operation name as a string literal. Serve is the method that serves the operation inside the operation middleware, with its signature; Context is the framework's context it takes first, when it reads path parameters from it. Bodies are the media types the handler tells apart, each once and never an empty one; Patterns are the keys that take the media types they match, application/*+json any JSON and a range such as text/* its type; Wildcards holds the body that takes any other media type, when the operation documents one such as */*. Tag is what the body switch is on, contentType, or empty when Patterns make it a switch of conditions; Empty is the case of a body without a media type.
type HeadersView ¶
HeadersView is a method that sets the typed headers of one status.
type ObjectView ¶
ObjectView is one object of the table, with its name quoted.
type OperationView ¶
type OperationView struct {
Name string
Method string
Path string
Doc string
Options string
Data string
Validation string
User map[string]any
Fields []FieldView
Checks []CheckView
Constructors []ConstructorView
Headers []HeadersView
}
OperationView is one operation: its method, options type and response data type. Method and Path are as the spec writes them. Fields are the parameter groups, then the bodies; Validation is set when there are checks.
type Options ¶
type Options struct {
Name string
Namer *naming.Namer
Framework framework.Framework
Descriptions bool
ValidateRequest bool
ValidateResponse bool
MultipartMaxMemory int64
Scaffold Scaffold
Port int
Timeout time.Duration
User map[string]any
RouterExtra string
}
Options are the settings of the server generator. Name is the base of the interface name. Scaffold flags say which scaffold files the config asks for. User is the config's user-context, which the overridable blocks see. RouterExtra is the router-extra override text. Descriptions copies the summary and description of each operation into its comment.
type ParamView ¶
type ParamView struct {
Decoder string
Source string
Target string
Name string
Location string
Style string
IsExplode bool
IsRequired bool
IsJSON bool
Default string
}
ParamView is one parameter: the runtime decoder, what it reads from, the options field it writes to, and its runtime.Param. Name and Location are quoted, Style a runtime constant.
type PresenceView ¶
type PresenceView struct {
Runtime string
IsChecked bool
Objects []ObjectView
}
PresenceView is the bodyPresence table. IsChecked adds the checks of validation.request.
type PropView ¶
type PropView struct {
Runtime string
Key string
IsRequired bool
IsNullable bool
Default string
Object string
Items *PropView
Values *PropView
}
PropView is a runtime.Prop. Key, Default and Object are quoted.
type RejectCaseView ¶
RejectCaseView is the error type that answers one status, every status when Status is 0. New is its constructor and MediaType is quoted.
type RejectView ¶
type RejectView struct {
IDs []string
Cases []RejectCaseView
}
RejectView answers the requests the operations of IDs, each quoted, turn away.
type RouteView ¶
type RouteView struct {
Method string
HTTPMethod string
Pattern string
Operation string
IsShortcut bool
Names []string
}
RouteView registers one operation: Method as the router's method, Get, HTTPMethod as the request writes it, GET, and Pattern quoted. IsShortcut marks a method routers have a function for, and Names are the route's Names, quoted.
type RouterView ¶
type RouterView struct {
Framework string
Packages map[string]string
Runtime string
HTTPServer string
Service string
Option string
Options string
NewOptions string
NewAdapter string
User map[string]any
Routes []RouteView
}
RouterView is the data of the router part. Framework is the name the framework's package is imported under and Packages the names of every package the framework imports, by the package's own name; the other names are written as the file spells them. User is the config's user-context. Runtime and HTTPServer are set when the template writes them.
type ScaffoldMainView ¶
type ScaffoldMainView struct {
Context string
HTTP string
Framework string
Packages map[string]string
Slog string
OS string
Signal string
Syscall string
NewRouter string
WithRouter string
WithConfig string
NewService string
WithMiddleware string
Middleware []string
Port int
Timeout string
}
ScaffoldMainView is the data of the main scaffold. Middleware lists the middleware expressions main passes, empty without the middleware scaffold; Timeout is a duration expression. HTTP is set for the shared template, which serves with an http.Server; Framework and Packages for the template of a framework that serves in its own way, as in the router's view. WithConfig is the option fiber and hertz make a new server with.
type ScaffoldMiddlewareView ¶
type ScaffoldMiddlewareView struct {
Context string
HTTP string
Slog string
Time string
Rand string
Debug string
}
ScaffoldMiddlewareView is the data of the middleware scaffold: the packages it imports.
type ScaffoldOperationView ¶
type ScaffoldOperationView struct {
Name string
Method string
Path string
Options string
Data string
User map[string]any
}
ScaffoldOperationView is one stub method.
type ScaffoldServiceView ¶
type ScaffoldServiceView struct {
Name string
Interface string
Context string
Errors string
User map[string]any
Operations []ScaffoldOperationView
}
ScaffoldServiceView is the data of the service scaffold: the struct named Name, which implements Interface. User is the config's user-context, which the blocks see.
type ServiceView ¶
type ServiceView struct {
Name string
Context string
HTTP string
Runtime string
User map[string]any
Operations []OperationView
}
ServiceView is the data of the service part. Context, HTTP and Runtime are the names the packages are imported under; User is the config's user-context.
type TypedErrorView ¶
TypedErrorView answers an error type of the spec with its status and quoted media type.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package framework is what the router of one HTTP framework needs from the generator, and what every framework shares.
|
Package framework is what the router of one HTTP framework needs from the generator, and what every framework shares. |
|
beego
Package beego is the router for github.com/beego/beego/v2.
|
Package beego is the router for github.com/beego/beego/v2. |
|
chi
Package chi is the router for github.com/go-chi/chi.
|
Package chi is the router for github.com/go-chi/chi. |
|
echo
Package echo is the router for github.com/labstack/echo, whose handlers take an echo.Context and return an error.
|
Package echo is the router for github.com/labstack/echo, whose handlers take an echo.Context and return an error. |
|
echov5
Package echov5 is the router for github.com/labstack/echo/v5, whose handlers take an *echo.Context and return an error.
|
Package echov5 is the router for github.com/labstack/echo/v5, whose handlers take an *echo.Context and return an error. |
|
fasthttp
Package fasthttp is the router for github.com/fasthttp/router over github.com/valyala/fasthttp.
|
Package fasthttp is the router for github.com/fasthttp/router over github.com/valyala/fasthttp. |
|
fiber
Package fiber is the router for github.com/gofiber/fiber/v3.
|
Package fiber is the router for github.com/gofiber/fiber/v3. |
|
gin
Package gin is the router for github.com/gin-gonic/gin.
|
Package gin is the router for github.com/gin-gonic/gin. |
|
goframe
Package goframe is the router for github.com/gogf/gf/v2.
|
Package goframe is the router for github.com/gogf/gf/v2. |
|
gorillamux
Package gorillamux is the router for github.com/gorilla/mux.
|
Package gorillamux is the router for github.com/gorilla/mux. |
|
gozero
Package gozero is the router for the rest package of github.com/zeromicro/go-zero: the router of its rest server, which rest.WithRouter gives one.
|
Package gozero is the router for the rest package of github.com/zeromicro/go-zero: the router of its rest server, which rest.WithRouter gives one. |
|
hertz
Package hertz is the router for github.com/cloudwego/hertz.
|
Package hertz is the router for github.com/cloudwego/hertz. |
|
iris
Package iris is the router for github.com/kataras/iris/v12.
|
Package iris is the router for github.com/kataras/iris/v12. |
|
kratos
Package kratos is the router for the HTTP transport of github.com/go-kratos/kratos/v2, whose handlers take a kratos Context and return an error.
|
Package kratos is the router for the HTTP transport of github.com/go-kratos/kratos/v2, whose handlers take a kratos Context and return an error. |
|
stdhttp
Package stdhttp is the router for http.ServeMux of the standard library, with its method and wildcard patterns.
|
Package stdhttp is the router for http.ServeMux of the standard library, with its method and wildcard patterns. |