Documentation ¶
Overview ¶
Stonelizard is a golang package that provides features to process HTTP requests on a Microservice architecture using REST, * Swagger and JSON technologies to communicate between services.
Example ¶
package main
import (
"os" "io" "fmt" "flag" "net/http" "github.com/luisfurquim/stonelizard" "github.com/luisfurquim/goose"
)
//Set your microservice Service struct
type Service struct { // defines the root of this service, and its meta data. root bool `root:"/concurso/" consumes:"application/json" produces:"application/json" allowGzip:"true" enableCORS:"true"` // endpoint for create new researches research bool `method:"POST" path:"/research/{researchnum}/xy/{User}" postdata:"RegisterRequestT"` //ignored because do not have root tag or field method yy int }
//Define your research struct
type ResearchRequestT struct { A int `json:"a"` B string `json:"b"` }
//Define variable to stored the work directory path var configPath string ```
func main() { var err error var svc Service flag.StringVar(&configPath,"conf", "./config.json", "Path to JSON configuration file") flag.Parse()
//If your use Goose package, define the log level necessary
Goose = goose.Alert(1) stonelizard.Goose = goose.Alert(1)
//Initialize the webservice using stonelizard.New() and ListenAndServerTLS() methods. The main flow is blocked waiting for new requests
svc = Service{yy:6} ws, err := stonelizard.New(&svc) if err != nil { fmt.Printf("Error: %s\n",err) os.Exit(1) } err = ws.ListenAndServeTLS() if err != nil { fmt.Println(err) } os.Exit(1) }
//Set the function that implements the endpoint service.
func (s *Service) Research(researchnum int, user string, data ResearchRequestT) stonelizard.Response { return stonelizard.Response{ Status: http.StatusOK, Body: fmt.Sprintf("Called research with %d and %s. Data:A=%d/B=%s. Internal object data: %d\n",researchnum,user,data.A,data.B,s.yy), } }
Index ¶
- Constants
- Variables
- func GetMethodInfo(fld reflect.StructField, OpType reflect.Type) (bool, string, reflect.Method)
- func GetWebSocketEventSpec(field reflect.StructField, WSMethodName string, WSMethod reflect.Method) (map[string]*SwaggerWSEventT, error)
- type AuthT
- type Base64Unmarshaler
- type DummyUnmarshaler
- type EndPointHandler
- type ExtAuthT
- type ExtAuthorizeIn
- type ExtAuthorizeOut
- type FileServerHandlerT
- type HandleHttpFn
- type HandleWsFn
- type Marshaler
- type Mod
- type MultipartUnmarshaler
- type Pki
- type PublicAccessT
- func (pa PublicAccessT) AddUserData(usrKey string, ClientCert *x509.Certificate) error
- func (pa PublicAccessT) Authorize(path string, parms map[string]interface{}, RemoteAddr string, ...) (httpstat int, data interface{}, err error)
- func (pa PublicAccessT) Delete(tree, id string) error
- func (pa PublicAccessT) Drop(id string) error
- func (pa PublicAccessT) GetCACert() *x509.Certificate
- func (pa PublicAccessT) GetCAKey() *rsa.PrivateKey
- func (pa PublicAccessT) GetCertPool() *x509.CertPool
- func (pa PublicAccessT) GetDNSNames() []string
- func (pa PublicAccessT) GetPending() (map[string]interface{}, error)
- func (pa PublicAccessT) GetServerCert() *x509.Certificate
- func (pa PublicAccessT) GetServerKey() *rsa.PrivateKey
- func (pa PublicAccessT) GetServerX509KeyPair() tls.Certificate
- func (pa PublicAccessT) GetTLSConfig(Access uint8) (*tls.Config, error)
- func (pa PublicAccessT) GetTrusted() (map[string]interface{}, error)
- func (pa PublicAccessT) LoadUserData() error
- func (pa PublicAccessT) ReadCertFromReader(r io.Reader) (*x509.Certificate, []byte, error)
- func (pa PublicAccessT) ReadCertificate(fname string) (*x509.Certificate, []byte, error)
- func (pa PublicAccessT) ReadDecryptRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error)
- func (pa PublicAccessT) ReadDecryptRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error)
- func (pa PublicAccessT) ReadRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error)
- func (pa PublicAccessT) ReadRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error)
- func (pa PublicAccessT) Reject(id string) error
- func (pa PublicAccessT) Setup(udata map[string]interface{}) error
- func (pa PublicAccessT) StartCRLServer(listenAddress string, listener *StoppableListener) error
- func (pa PublicAccessT) Trust(id string) error
- type ReadCloser
- type Response
- type ResponseT
- type ResponseWriter
- type SLFileSystem
- type Service
- func (svc Service) Close()
- func (svc *Service) FetchEndpointHandler(proto, method, path string) (*UrlNode, []interface{}, map[string]interface{}, int)
- func (svc *Service) ListenAndServeTLS() error
- func (svc *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (svc Service) String() string
- type ServiceWithPKI
- type Shaper
- type Static
- type StaticBase64
- type StaticSvc
- type StonelizardG
- type StoppableListener
- type SwaggerContactT
- type SwaggerEventParameterT
- type SwaggerExternalDocsT
- type SwaggerHeaderT
- type SwaggerInfoT
- type SwaggerItemT
- type SwaggerLicenseT
- type SwaggerOperationT
- type SwaggerParameterT
- type SwaggerPathT
- type SwaggerResponseT
- type SwaggerSchemaT
- type SwaggerSecDefsT
- type SwaggerSecurityT
- type SwaggerT
- type SwaggerTagT
- type SwaggerWSEventT
- type SwaggerWSOperationT
- type SwaggerXmlT
- type Unmarshaler
- type UrlNode
- type Void
- type WSEventTrigger
- type WSocketEventRegistry
- type WSocketOperation
Constants ¶
const ( AccessNone uint8 = iota AccessAuth AccessAuthInfo AccessVerifyAuth AccessVerifyAuthInfo AccessInfo )
const StatusTrigEvent = 275
const StatusTrigEventDescription = "Trig Event"
Variables ¶
var ErrorCannotWrapListener = errors.New("Cannot wrap listener")
var ErrorConversionOverflow = errors.New("Conversion overflow")
var ErrorDecodeError = errors.New("Decode error")
var ErrorDescriptionSyntax = errors.New("Syntax error on response description")
var ErrorEndEventTriggering = errors.New("End event triggering")
var ErrorFieldIsOfWSEventTriggerTypeButUnexported = errors.New("Field is of Event Trigger type, but it is not exported")
var ErrorInvalidNilParam = errors.New("Syntax error nil parameter not allowed in this context")
var ErrorInvalidParameterType = errors.New("Invalid parameter type")
var ErrorInvalidProtocol = errors.New("Invalid protocol")
var ErrorInvalidType = errors.New("Invalid type")
var ErrorMissingRequiredHTTPHeader = errors.New("Missing required HTTP header")
var ErrorMissingRequiredPostBodyField = errors.New("Error missing required post body field")
var ErrorMissingRequiredQueryField = errors.New("Error missing required query field")
var ErrorMissingWebsocketInTagSyntax = errors.New("Syntax error missing websocket 'in' tag")
var ErrorMixedProtocol = errors.New("Mixed http/https with ws/wss")
var ErrorNoRoot = errors.New("No service root specified")
var ErrorParmListSyntax = errors.New("Syntax error on parameter list")
var ErrorServiceSyntax = errors.New("Syntax error on service definition")
var ErrorStopEventTriggering = errors.New("Stop event triggering")
var ErrorStopped = errors.New("Stop signal received")
var ErrorUndefMod = errors.New("Undefined module")
var ErrorUndefPropType = errors.New("Undefined property type")
var ErrorWrongAuthorizerReturnValues = errors.New("Error wrong authorizer return values")
var ErrorWrongHandlerKind = errors.New("Wrong handler kind")
var ErrorWrongParameterCount = errors.New("Wrong parameter count")
var MapParameterEncodingError = errors.New("Map parameter encoding error")
var MaxUploadMemory int64 = 16 * 1024 * 1024
var ModType = reflect.TypeOf(Mod{})
var WrongParameterLength = errors.New("Wrong parameter length")
var WrongParameterType = errors.New("Wrong parameter type")
Functions ¶
func GetMethodInfo ¶
Returns if a method name, if it is pointer referenced and its reflect definition It receives the unexported field from the service definition struct and searches for a method with same name but with an uppercase first letter
func GetWebSocketEventSpec ¶
func GetWebSocketEventSpec(field reflect.StructField, WSMethodName string, WSMethod reflect.Method) (map[string]*SwaggerWSEventT, error)
Returns a swagger definition of all the events defined by type of the struct field "field"
Types ¶
type AuthT ¶
type AuthT interface { GetTLSConfig(Access uint8) (*tls.Config, error) StartCRLServer(listenAddress string, listener *StoppableListener) error GetDNSNames() []string Authorize(path string, parms map[string]interface{}, RemoteAddr string, TLS *tls.ConnectionState, SavePending func(interface{}) error) (httpstat int, data interface{}, err error) GetServerCert() *x509.Certificate GetServerKey() *rsa.PrivateKey GetCACert() *x509.Certificate GetCAKey() *rsa.PrivateKey GetServerX509KeyPair() tls.Certificate GetCertPool() *x509.CertPool ReadCertFromReader(r io.Reader) (*x509.Certificate, []byte, error) ReadCertificate(fname string) (*x509.Certificate, []byte, error) ReadRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error) ReadRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error) ReadDecryptRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error) ReadDecryptRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error) Setup(udata map[string]interface{}) error LoadUserData() error AddUserData(usrKey string, ClientCert *x509.Certificate) error Trust(id string) error Reject(id string) error Drop(id string) error Delete(tree, id string) error GetPending() (map[string]interface{}, error) GetTrusted() (map[string]interface{}, error) }
AuthT interface defines an authorizer function To use it put an anonymous field that satisfies the AuthT interface in the EndPointHandler provided to stonelizard.New Input (
@method: HTTP method @path: the path part of the URL of the operation as it appears in your EndPointHandler definition @parms: the key is the parameter name as defined in your EndPointHandler definition, the value is the one sent by the requesting client @RemoteAddr: the remote client address @TLS: the TLS connection information received from the client, may be nil @SavePending: function to save pending authorization information. It receives one interface{} argument with the info to be saved for later 3rd party analysis. It may be just NOOP function, Authorize implementations SHOULD NOT trust that the info is really being saved.
) Output (
@httpstat: HTTP status code (used only if error is not nil) @data: if the operation has a tag 'access' with value 'authinfo', this data is passed to the operation method as the last parameter (remember to declare it as interface{}). This setting is not added to the swagger.json generated or any other generated service description. @err: error status (if it is not nil, the operation method is not called and the error message is sent to the client, along with the http status code)
)
type Base64Unmarshaler ¶
type Base64Unmarshaler struct {
// contains filtered or unexported fields
}
func NewBase64Unmarshaler ¶
func NewBase64Unmarshaler(r *http.Request) *Base64Unmarshaler
Creates a Base64 Unmarshaler
func (*Base64Unmarshaler) Decode ¶
func (b *Base64Unmarshaler) Decode(v interface{}) error
Fetches the next value from the HTTP POST vars
type DummyUnmarshaler ¶
type DummyUnmarshaler struct {
// contains filtered or unexported fields
}
func NewDummyUnmarshaler ¶
func NewDummyUnmarshaler(r *http.Request) *DummyUnmarshaler
Creates a Dummy Unmarshaler
func (*DummyUnmarshaler) Decode ¶
func (b *DummyUnmarshaler) Decode(v interface{}) error
Fetches the next value from the HTTP POST vars
type EndPointHandler ¶
type ExtAuthT ¶
type ExtAuthT interface { ExtAuthorize(ch chan ExtAuthorizeIn, path string, parms map[string]interface{}, resp http.ResponseWriter, req *http.Request, SavePending func(interface{}) error) (httpstat int, data interface{}, err error) StartExtAuthorizer(authReq chan ExtAuthorizeIn) }
ExtAuthT interface defines an extended authorizer function. If stonelizard detects that your authorizer also satisfies this interface, then ExtAuthorize will be used INSTEAD of Authorize. Input (
@ch: channel to send authorizer request data @path: the path part of the URL of the operation as it appears in your EndPointHandler definition @parms: the key is the parameter name as defined in your EndPointHandler definition, the value is the one sent by the requesting client @request: the entire http request object @SavePending: function to save pending authorization information. It receives one interface{} argument with the info to be saved for later 3rd party analysis. It may be just NOOP function, Authorize implementations SHOULD NOT trust that the info is really being saved.
) Output (
@httpstat: HTTP status code (used only if error is not nil) @data: if the operation has a tag 'access' with value 'authinfo', this data is passed to the operation method as the last parameter (remember to declare it as interface{}). This setting is not added to the swagger.json generated or any other generated service description. @err: error status (if it is not nil, the operation method is not called and the error message is sent to the client, along with the http status code)
)
type ExtAuthorizeIn ¶
type ExtAuthorizeIn struct { Path string Parms map[string]interface{} Resp http.ResponseWriter Req *http.Request SavePending func(interface{}) error Out chan ExtAuthorizeOut }
type ExtAuthorizeOut ¶
type FileServerHandlerT ¶
type FileServerHandlerT struct {
// contains filtered or unexported fields
}
func (FileServerHandlerT) ServeHTTP ¶
func (fs FileServerHandlerT) ServeHTTP(w http.ResponseWriter, r *http.Request)
type HandleHttpFn ¶
type HandleHttpFn func([]interface{}, Unmarshaler, interface{}, string, string) Response // Operation handler function, it calls the method defined by the application
type HandleWsFn ¶
type HandleWsFn func([]interface{}, Unmarshaler) Response // Operation handler function, it calls the method defined by the application
type MultipartUnmarshaler ¶
type MultipartUnmarshaler struct {
// contains filtered or unexported fields
}
func NewMultipartUnmarshaler ¶
func NewMultipartUnmarshaler(r *http.Request, fields []string) (*MultipartUnmarshaler, error)
Creates a Multipart Unmarshaler
func (*MultipartUnmarshaler) Decode ¶
func (mp *MultipartUnmarshaler) Decode(v interface{}) error
Fetches the next value from the HTTP POST vars
func (MultipartUnmarshaler) More ¶
func (mp MultipartUnmarshaler) More() bool
type Pki ¶
type Pki interface { GenerateClientCSR(subject pkix.Name, email string) ([]byte, error) GenerateClient(asn1Data []byte) (*x509.Certificate, *rsa.PublicKey, error) NewPemCertReqFromReader(rd io.Reader) error NewPemCertFromMemory(buf []byte) error NewPemCertFromReader(rd io.Reader) error NewPemCertFromFile(fname string) error NewPemKeyFromMemory(buf []byte, password string) error NewPemKeyFromReader(rd io.Reader, password string) error NewPemKeyFromFile(fname string, password string) error PemKey(password string) ([]byte, error) PemKeyToFile(fname, password string) error PemCsr(der []byte, fname string) error NewPemCert(fname string) error Sign(msg string) ([]byte, error) Verify(msg string, signature []byte) error Encrypt(msg []byte) ([]byte, error) Decrypt(secret []byte) ([]byte, error) Challenge() ([]byte, []byte, error) QrKeyId(keyId string, challenge []byte) ([]byte, error) FindCertificate(keyId string) (Pki, string, error) Certificate() []byte }
type PublicAccessT ¶
type PublicAccessT struct{}
func (PublicAccessT) AddUserData ¶
func (pa PublicAccessT) AddUserData(usrKey string, ClientCert *x509.Certificate) error
func (PublicAccessT) Authorize ¶
func (pa PublicAccessT) Authorize(path string, parms map[string]interface{}, RemoteAddr string, TLS *tls.ConnectionState, SavePending func(interface{}) error) (httpstat int, data interface{}, err error)
func (PublicAccessT) Delete ¶
func (pa PublicAccessT) Delete(tree, id string) error
func (PublicAccessT) Drop ¶
func (pa PublicAccessT) Drop(id string) error
func (PublicAccessT) GetCACert ¶
func (pa PublicAccessT) GetCACert() *x509.Certificate
func (PublicAccessT) GetCAKey ¶
func (pa PublicAccessT) GetCAKey() *rsa.PrivateKey
func (PublicAccessT) GetCertPool ¶
func (pa PublicAccessT) GetCertPool() *x509.CertPool
func (PublicAccessT) GetDNSNames ¶
func (pa PublicAccessT) GetDNSNames() []string
func (PublicAccessT) GetPending ¶
func (pa PublicAccessT) GetPending() (map[string]interface{}, error)
func (PublicAccessT) GetServerCert ¶
func (pa PublicAccessT) GetServerCert() *x509.Certificate
func (PublicAccessT) GetServerKey ¶
func (pa PublicAccessT) GetServerKey() *rsa.PrivateKey
func (PublicAccessT) GetServerX509KeyPair ¶
func (pa PublicAccessT) GetServerX509KeyPair() tls.Certificate
func (PublicAccessT) GetTLSConfig ¶
func (pa PublicAccessT) GetTLSConfig(Access uint8) (*tls.Config, error)
func (PublicAccessT) GetTrusted ¶
func (pa PublicAccessT) GetTrusted() (map[string]interface{}, error)
func (PublicAccessT) LoadUserData ¶
func (pa PublicAccessT) LoadUserData() error
func (PublicAccessT) ReadCertFromReader ¶
func (pa PublicAccessT) ReadCertFromReader(r io.Reader) (*x509.Certificate, []byte, error)
func (PublicAccessT) ReadCertificate ¶
func (pa PublicAccessT) ReadCertificate(fname string) (*x509.Certificate, []byte, error)
func (PublicAccessT) ReadDecryptRsaPrivKey ¶
func (pa PublicAccessT) ReadDecryptRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error)
func (PublicAccessT) ReadDecryptRsaPrivKeyFromReader ¶
func (pa PublicAccessT) ReadDecryptRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error)
func (PublicAccessT) ReadRsaPrivKey ¶
func (pa PublicAccessT) ReadRsaPrivKey(fname string) (*rsa.PrivateKey, []byte, error)
func (PublicAccessT) ReadRsaPrivKeyFromReader ¶
func (pa PublicAccessT) ReadRsaPrivKeyFromReader(r io.Reader) (*rsa.PrivateKey, []byte, error)
func (PublicAccessT) Reject ¶
func (pa PublicAccessT) Reject(id string) error
func (PublicAccessT) Setup ¶
func (pa PublicAccessT) Setup(udata map[string]interface{}) error
func (PublicAccessT) StartCRLServer ¶
func (pa PublicAccessT) StartCRLServer(listenAddress string, listener *StoppableListener) error
func (PublicAccessT) Trust ¶
func (pa PublicAccessT) Trust(id string) error
type ReadCloser ¶
func NewReadCloser ¶
func NewReadCloser(src []byte) ReadCloser
func (ReadCloser) Close ¶
func (rc ReadCloser) Close() error
type ResponseWriter ¶
type SLFileSystem ¶
type Service ¶
type Service struct { Matcher *regexp.Regexp MatchedOps map[int]int Svc []UrlNode Config Shaper AuthRequired bool AllowGzip bool EnableCORS bool Proto []string Listener *StoppableListener CRLListener *StoppableListener Swagger *SwaggerT Access uint8 Authorizer AuthT SavePending func(interface{}) error PlainStatic map[string]StaticSvc SecureStatic map[string]StaticSvc SwaggerPath string // contains filtered or unexported fields }
func New ¶
func New(svcs ...EndPointHandler) (*Service, error)
func (*Service) FetchEndpointHandler ¶
func (*Service) ListenAndServeTLS ¶
Init a webserver and wait for http requests.
type ServiceWithPKI ¶
func NewWithPKI ¶
func NewWithPKI(pk Pki, svcs ...EndPointHandler) (*ServiceWithPKI, error)
func (*ServiceWithPKI) ListenAndServeTLS ¶
func (svc *ServiceWithPKI) ListenAndServeTLS() error
Init a webserver and wait for http requests.
func (*ServiceWithPKI) ServeHTTP ¶
func (svc *ServiceWithPKI) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Shaper ¶
type Shaper interface { PageNotFound() []byte ListenAddress() string CRLListenAddress() string CertKit() AuthT }
Shaper interface has an optional method: SavePending(cert *x509.Certificate) error
type Static ¶
type Static struct {
// contains filtered or unexported fields
}
func NewStaticEncoder ¶
type StaticBase64 ¶
type StaticBase64 struct {
// contains filtered or unexported fields
}
func NewStaticBase64Encoder ¶
func NewStaticBase64Encoder(w io.Writer) *StaticBase64
func (*StaticBase64) Encode ¶
func (d *StaticBase64) Encode(v interface{}) error
type StonelizardG ¶
type StonelizardG struct { Listener goose.Alert Swagger goose.Alert Initialize goose.Alert OpHandle goose.Alert ParseFields goose.Alert New goose.Alert InitServe goose.Alert Serve goose.Alert Auth goose.Alert }
var Goose StonelizardG
type StoppableListener ¶
type StoppableListener struct { *net.TCPListener // Wrapped listener // contains filtered or unexported fields }
func NewListener ¶
func NewListener(l net.Listener) (*StoppableListener, error)
Init the listener for the service.
func (*StoppableListener) Accept ¶
func (sl *StoppableListener) Accept() (net.Conn, error)
http://www.hydrogen18.com/blog/stop-listening-http-server-go.html Implements a wrapper on the system accept
func (*StoppableListener) Stop ¶
func (sl *StoppableListener) Stop()
Stop the service and releases the channel
type SwaggerContactT ¶
type SwaggerContactT struct { // The identifying name of the contact person/organization. Name string `json:"name"` // The URL pointing to the contact information. MUST be in the format of a URL. Url string `json:"url"` // The email address of the contact person/organization. MUST be in the format of an email address. Email string `json:"email"` }
type SwaggerEventParameterT ¶
type SwaggerEventParameterT struct { Name string `json:"name"` // GFM syntax can be used for rich text representation Description *string `json:"description,omitempty"` // The type of the parameter / The internal type of the array. // Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). // The value MUST be one of "string", "number", "integer", "boolean", "array" or "file" (Files and models are not allowed in arrays). // If type is "file", the consumes MUST be either "multipart/form-data" or " application/x-www-form-urlencoded" and the parameter MUST be in "formData". Type string `json:"type"` // The extending format for the previously mentioned type. See Data Type Formats for further details. Format string `json:"format,omitempty"` // If Type is "array", this must show a list of its items. // The list MUST NOT include duplicated parameters. // If type Items []SwaggerEventParameterT `json:"items,omitempty"` // Declares this operation to be deprecated. // Usage of the declared operation should be refrained. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` // Determines whether this parameter is mandatory. // If the parameter is in "path", this property is required and its value MUST be true. // Otherwise, the property MAY be included and its default value is false. Required bool `json:"required,omitempty"` }
type SwaggerExternalDocsT ¶
type SwaggerExternalDocsT struct { // A short description of the target documentation. // GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // The URL for the target documentation. // Value MUST be in the format of a URL. Url string `json:"url"` }
type SwaggerHeaderT ¶
type SwaggerHeaderT struct { // The type of the parameter / The internal type of the array. // Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). // The value MUST be one of "string", "number", "integer", "boolean", "array" or "file" (Files and models are not allowed in arrays). // If type is "file", the consumes MUST be either "multipart/form-data" or " application/x-www-form-urlencoded" and the parameter MUST be in "formData". Type string `json:"type"` // Required if type is "array". Describes the type of items in the array. Items *SwaggerItemT `json:"items,omitempty"` // The extending format for the previously mentioned type. See Data Type Formats for further details. Format string `json:"format,omitempty"` // Declares the value of the parameter that the server will use if none is provided, // for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. // (Note: "default" has no meaning for required parameters.) // See http://json-schema.org/latest/json-schema-validation.html#anchor101. // Unlike JSON Schema this value MUST conform to the defined type for this parameter. Default interface{} `json:"default,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. Maximum string `json:"maximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. Minimum string `json:"minimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor26. MaxLength int64 `json:"maxLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor29. MinLength int64 `json:"minLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor33. Pattern string `json:"pattern,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor42. MaxItems int64 `json:"maxItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor45. MinItems int64 `json:"minItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor49. UniqueItems bool `json:"uniqueItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor76. Enum []interface{} `json:"enum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor14. MultipleOf string `json:"multipleOf,omitempty"` // contains filtered or unexported fields }
type SwaggerInfoT ¶
type SwaggerInfoT struct { // The title of the application. Title string `json:"title"` // A short description of the application. // GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // The Terms of Service for the API. TermsOfService string `json:"termsOfService,omitempty"` // The contact information for the exposed API. Contact SwaggerContactT `json:"contact,omitempty"` // The license information for the exposed API. License SwaggerLicenseT `json:"license,omitempty"` // Provides the version of the application API (not to be confused with the specification version). Version string `json:"version"` // Custom stonelizard field used to tell clients how to group client variables // Used to automatically generate client code // The first index is the module name, the second index is the property name XModules map[string]map[string]*SwaggerSchemaT `json:"x-modules,omitempty"` }
type SwaggerItemT ¶
type SwaggerItemT struct { // The type of the parameter / The internal type of the array. // Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). // The value MUST be one of "string", "number", "integer", "boolean", "array" or "file" (Files and models are not allowed in arrays). // If type is "file", the consumes MUST be either "multipart/form-data" or " application/x-www-form-urlencoded" and the parameter MUST be in "formData". Type string `json:"type"` // Required if type is "array". Describes the type of items in the array. Items *SwaggerItemT `json:"items,omitempty"` // The extending format for the previously mentioned type. See Data Type Formats for further details. Format string `json:"format,omitempty"` // Declares the value of the parameter that the server will use if none is provided, // for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. // (Note: "default" has no meaning for required parameters.) // See http://json-schema.org/latest/json-schema-validation.html#anchor101. // Unlike JSON Schema this value MUST conform to the defined type for this parameter. Default interface{} `json:"default,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. Maximum string `json:"maximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. Minimum string `json:"minimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor26. MaxLength int64 `json:"maxLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor29. MinLength int64 `json:"minLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor33. Pattern string `json:"pattern,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor42. MaxItems int64 `json:"maxItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor45. MinItems int64 `json:"minItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor49. UniqueItems bool `json:"uniqueItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor76. Enum []interface{} `json:"enum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor14. MultipleOf string `json:"multipleOf,omitempty"` // Determines the format of the array if type array is used. Possible values are: // csv - comma separated values foo,bar. // ssv - space separated values foo bar. // tsv - tab separated values foo\tbar. // pipes - pipe separated values foo|bar. // multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz. This is valid only for parameters in "query" or "formData". // Default value is csv. CollectionFormat string `json:"collectionFormat,omitempty"` // Custom stonelizard extension. Specifies the type of the key. Used for key-value data types XKeyType string `json:"x-keytype,omitempty"` // Custom stonelizard extension. Specifies the format of the key. Used for key-value data types XKeyFormat string `json:"x-keyformat,omitempty"` }
type SwaggerLicenseT ¶
type SwaggerOperationT ¶
type SwaggerOperationT struct { // A list of tags for API documentation control. // Tags can be used for logical grouping of operations by resources or any other qualifier. Tags []string `json:"tags,omitempty"` // A short summary of what the operation does. // For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters. Summary string `json:"summary,omitempty"` // A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this operation. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` // Unique string used to identify the operation. // The id MUST be unique among all operations described in the API. // Tools and libraries MAY use the operationId to uniquely identify an operation, therefore, // it is recommended to follow common programming naming conventions. OperationId string `json:"operationId,omitempty"` // A list of MIME types the operation can consume. // This overrides the consumes definition at the Swagger Object. // An empty value MAY be used to clear the global definition. // Value MUST be as described under Mime Types. Consumes []string `json:"consumes,omitempty"` // A list of MIME types the operation can produce. // This overrides the produces definition at the Swagger Object. // An empty value MAY be used to clear the global definition. // Value MUST be as described under Mime Types. Produces []string `json:"produces,omitempty"` // A list of parameters that are applicable for this operation. // If a parameter is already defined at the Path Item, the new definition will override it, but can never remove it. // The list MUST NOT include duplicated parameters. // A unique parameter is defined by a combination of a name and location. // The list can use the Reference Object to link to parameters that are defined at the Swagger Object's parameters. // There can be one "body" parameter at most. Parameters []SwaggerParameterT `json:"parameters,omitempty"` // Required. The list of possible responses as they are returned from executing this operation. Responses map[string]SwaggerResponseT `json:"responses"` // The transfer protocol for the operation. // Values MUST be from the list: "http", "https", "ws", "wss". // The value overrides the Swagger Object schemes definition. Schemes []string `json:"schemes,omitempty"` // Declares this operation to be deprecated. // Usage of the declared operation should be refrained. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` // A declaration of which security schemes are applied for this operation. // The list of values describes alternative security schemes that can be used // (that is, there is a logical OR between the security requirements). // This definition overrides any declared top-level security. // To remove a top-level security declaration, an empty array can be used. Security map[string]SwaggerSecurityT `json:"security,omitempty"` // Custom stonelizard extension. Specifies suboperations. Used for websocket operations. // The HTTP connection is upgraded to websocket connection only if the operation returns a 2XX HTTP status code. XWSOperations map[string]*SwaggerWSOperationT `json:"x-websocketoperations,omitempty"` // Custom stonelizard extension. Specifies events. Used for websocket operations. // Events only fire if the HTTP connection is upgraded to websocket connection and subjected to application specific // semantics/rules. XWSEvents map[string]*SwaggerWSEventT `json:"x-websocketevents,omitempty"` // Custom stonelizard extension. A list of websocket subprotocols the operation can consume. // At this moment, it only accepts the stonelizard's non-standard 'sam+json', which stands for 'JSON encoded simple array messaging'. XWSConsumes []string `json:"x-websocketconsumes,omitempty"` // Custom stonelizard extension. It doesn't affect the web service operation. // It is intended to provide developers a way to organize their web service client code. // Our suggestion is that operations belonging to the same module be accesssed using // the same class. But it is not mandatory. XModule string `json:"x-module,omitempty"` // Custom stonelizard extension. It doesn't affect the web service operation. // It is intended to provide developers a way to handle the returned data. // Our suggestion is to use this info to give clients a hint on WHERE to store // the return data XOutputVar string `json:"x-outputvar,omitempty"` // Custom stonelizard extension. It doesn't affect the web service operation. // It is intended to provide developers a way to handle the returned data. // Our suggestion is to use this info to give clients a hint on HOW to store // the return data XOutput string `json:"x-output,omitempty"` }
type SwaggerParameterT ¶
type SwaggerParameterT struct { // If in is "path", the name field MUST correspond to the associated path segment from the path field in the Paths Object. // See Path Templating for further information. // For all other cases, the name corresponds to the parameter name used based on the in property. // The name of the parameter. Parameter names are case sensitive. Name string `json:"name"` // The location of the parameter. // Possible values are "query", "header", "path", "formData" or "body". In string `json:"in"` // A brief description of the parameter. // This could contain examples of use. // GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // Determines whether this parameter is mandatory. // If the parameter is in "path", this property is required and its value MUST be true. // Otherwise, the property MAY be included and its default value is false. Required bool `json:"required"` // The schema defining the type used for the body parameter. Schema *SwaggerSchemaT `json:"schema,omitempty"` // required if in=="body" // Sets the ability to pass empty-valued parameters. // This is valid only for either query or formData parameters and allows you to send a parameter with a name only or an empty value. // Default value is false. AllowEmptyValue bool `json:"allowEmptyValue,omitempty"` // The type of the parameter / The internal type of the array. // Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). // The value MUST be one of "string", "number", "integer", "boolean", "array" or "file" (Files and models are not allowed in arrays). // If type is "file", the consumes MUST be either "multipart/form-data" or " application/x-www-form-urlencoded" and the parameter MUST be in "formData". Type string `json:"type,omitempty"` // The extending format for the previously mentioned type. See Data Type Formats for further details. Format string `json:"format,omitempty"` // Declares the value of the parameter that the server will use if none is provided, // for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. // (Note: "default" has no meaning for required parameters.) // See http://json-schema.org/latest/json-schema-validation.html#anchor101. // Unlike JSON Schema this value MUST conform to the defined type for this parameter. Default interface{} `json:"default,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. Maximum string `json:"maximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. Minimum string `json:"minimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor26. MaxLength int64 `json:"maxLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor29. MinLength int64 `json:"minLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor33. Pattern string `json:"pattern,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor42. MaxItems int64 `json:"maxItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor45. MinItems int64 `json:"minItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor49. UniqueItems bool `json:"uniqueItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor76. Enum []interface{} `json:"enum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor14. MultipleOf string `json:"multipleOf,omitempty"` // Determines the format of the array if type array is used. Possible values are: // csv - comma separated values foo,bar. // ssv - space separated values foo bar. // tsv - tab separated values foo\tbar. // pipes - pipe separated values foo|bar. // multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz. This is valid only for parameters in "query" or "formData". // Default value is csv. CollectionFormat string `json:"collectionFormat,omitempty"` // Custom stonelizard extension. Currently it only accepts cskv (comma separated key-values: k1:v1,...,kn:vn) XCollectionFormat string `json:"x-collectionFormat,omitempty"` // Custom stonelizard extension. Specifies the type of the key. Used for key-value data types XKeyType string `json:"x-keytype,omitempty"` // Custom stonelizard extension. Specifies the format of the key. Used for key-value data types XKeyFormat string `json:"x-keyformat,omitempty"` }
func GetSwaggerType ¶
func GetSwaggerType(parm reflect.Type) (*SwaggerParameterT, error)
Returns a swagger definition of the type received Scalar types are just a simple type string and maybe a format specification Nils are nils :P Pointers get de-referenced and then we recurse Aggregated types (array/slice, map and struct) needs more burocracy, but they all end up recursing until we reach the scalar types
func ParseFieldList ¶
func ParseFieldList(listEncoding string, parmcountIn int, fld reflect.StructField, method reflect.Method, methodName string, swaggerParametersIn []SwaggerParameterT) (list []string, parmcount int, pt reflect.Type, swaggerParameters []SwaggerParameterT, err error)
Consider this example tag: `query:"field1,field2" field1:"This is the first parameter for this operation"` Searches for a listEncoding ('query' in this example) and returns a swagger list of parameters with 2 parameters ("field1" and "field2") the parameter "field1" will have a documentation based on the text provided by the tag "field1", the parameter "field2" will have no documentation
type SwaggerPathT ¶
type SwaggerPathT map[string]*SwaggerOperationT
type SwaggerResponseT ¶
type SwaggerResponseT struct { // A short description of the response. GFM syntax can be used for rich text representation. Description string `json:"description"` // A definition of the response structure. // It can be a primitive, an array or an object. // If this field does not exist, it means no content is returned as part of the response. // As an extension to the Schema Object, its root type value may also be "file". // This SHOULD be accompanied by a relevant produces mime-type. Schema *SwaggerSchemaT `json:"schema,omitempty"` // A list of headers that are sent with the response. Headers map[string]SwaggerHeaderT `json:"headers,omitempty"` // An example of the response message. Examples map[string]interface{} `json:"examples,omitempty"` }
type SwaggerSchemaT ¶
type SwaggerSchemaT struct { Title string `json:"title,omitempty"` // GFM syntax can be used for rich text representation Description *string `json:"description,omitempty"` // The type of the parameter / The internal type of the array. // Since the parameter is not located at the request body, it is limited to simple types (that is, not an object). // The value MUST be one of "string", "number", "integer", "boolean", "array" or "file" (Files and models are not allowed in arrays). // If type is "file", the consumes MUST be either "multipart/form-data" or " application/x-www-form-urlencoded" and the parameter MUST be in "formData". Type string `json:"type"` // Required if type is "array". Describes the type of items in the array. // Items *SwaggerItemT `json:"items,omitempty"` Items *SwaggerSchemaT `json:"items,omitempty"` // The extending format for the previously mentioned type. See Data Type Formats for further details. Format string `json:"format,omitempty"` // Declares the value of the parameter that the server will use if none is provided, // for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. // (Note: "default" has no meaning for required parameters.) // See http://json-schema.org/latest/json-schema-validation.html#anchor101. // Unlike JSON Schema this value MUST conform to the defined type for this parameter. Default interface{} `json:"default,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. Maximum string `json:"maximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor17. ExclusiveMaximum bool `json:"exclusiveMaximum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. Minimum string `json:"minimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor21. ExclusiveMinimum bool `json:"exclusiveMinimum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor26. MaxLength int64 `json:"maxLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor29. MinLength int64 `json:"minLength,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor33. Pattern string `json:"pattern,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor42. MaxItems int64 `json:"maxItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor45. MinItems int64 `json:"minItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor49. UniqueItems bool `json:"uniqueItems,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor76. Enum []interface{} `json:"enum,omitempty"` // See http://json-schema.org/latest/json-schema-validation.html#anchor14. MultipleOf string `json:"multipleOf,omitempty"` // The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword. MaxProperties uint64 `json:"maxProperties,omitempty"` // The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. // An object instance is valid against "maxProperties" if its number of properties is more than, or equal to, the value of this keyword. MinProperties uint64 `json:"minProperties,omitempty"` // Lists which of the objetct properties are mandatory. Required []string `json:"required,omitempty"` // This keyword's value MUST be an array. This array MUST have at least one element. // Elements of the array MUST be objects. Each object MUST be a valid Swagger JSON Schema. // An instance validates successfully against this keyword if it validates successfully against all schemas defined by this keyword's value. AllOf []*SwaggerSchemaT `json:"allOf,omitempty"` Properties map[string]SwaggerSchemaT `json:"properties,omitempty"` // The value of "additionalProperties" MUST be a boolean or an object. // If it is an object, it MUST also be a valid JSON Schema. // SL: Always a schema... AdditionalProperties *SwaggerSchemaT `json:"additionalProperties,omitempty"` // Adds support for polymorphism. // The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. // The property name used MUST be defined at this schema and it MUST be in the required property list. // When used, the value MUST be the name of this schema or any schema that inherits it. Discriminator string `json:"discriminator,omitempty"` // Relevant only for Schema "properties" definitions. // Declares the property as "read only". // This means that it MAY be sent as part of a response but MUST NOT be sent as part of the request. // Properties marked as readOnly being true SHOULD NOT be in the required list of the defined schema. // Default value is false. ReadOnly bool `json:"readOnly,omitempty"` // This MAY be used only on properties schemas. // It has no effect on root schemas. // Adds Additional metadata to describe the XML representation format of this property. Xml *SwaggerXmlT `json:"xml,omitempty"` // External Documentation Object Additional external documentation for this schema. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` // A free-form property to include a an example of an instance for this schema. Example interface{} `json:"example,omitempty"` // Custom stonelizard extension. Currently it only accepts cskv (comma separated key-values: k1:v1,...,kn:vn) XCollectionFormat string `json:"x-collectionFormat,omitempty"` // Custom stonelizard extension. Specifies the type of the key. Used for key-value data types XKeyType string `json:"x-keytype,omitempty"` // Custom stonelizard extension. Specifies the format of the key. Used for key-value data types XKeyFormat string `json:"x-keyformat,omitempty"` }
type SwaggerSecDefsT ¶
type SwaggerSecDefsT struct { // Validity: Any // Required. The type of the security scheme. Valid values are "basic", "apiKey" or "oauth2". Type string `json:"type"` // Validity: Any // A short description for security scheme. Description string `json:"description,omitempty"` // Validity: apiKey Required. // The name of the header or query parameter to be used. Name string `json:"name"` // Validity: apiKey Required // The location of the API key. Valid values are "query" or "header". In string `json:"in"` // Validity: oauth2 Required. // The flow used by the OAuth2 security scheme. Valid values are "implicit", "password", "application" or "accessCode". Flow string `json:"flow"` // Validity: oauth2 ("implicit", "accessCode") Required. // The authorization URL to be used for this flow. This SHOULD be in the form of a URL. AuthorizationUrl string `json:"authorizationUrl"` // Validity: oauth2 ("password", "application", "accessCode") Required. // The token URL to be used for this flow. This SHOULD be in the form of a URL. TokenUrl string `json:"tokenUrl"` // Validity: oauth2 Required. // The available scopes for the OAuth2 security scheme. // Maps between a name of a scope to a short description of it (as the value of the property). Scopes map[string]string `json:"scopes"` }
type SwaggerSecurityT ¶
type SwaggerSecurityT []string
type SwaggerT ¶
type SwaggerT struct { // Required. Specifies the Swagger Specification version being used. // It can be used by the Swagger UI and other clients to interpret the API listing. // The value MUST be "2.0". Version string `json:"swagger"` // Required. Provides metadata about the API. // The metadata can be used by the clients if needed. Info SwaggerInfoT `json:"info"` // The host (name or ip) serving the API. // This MUST be the host only and does not include the scheme nor sub-paths. // It MAY include a port. If the host is not included, the host serving the documentation is to be used (including the port). // The host does not support path templating. Host string `json:"host,omitempty"` // The base path on which the API is served, which is relative to the host. // If it is not included, the API is served directly under the host. // The value MUST start with a leading slash (/). // The basePath does not support path templating. BasePath string `json:"basePath,omitempty"` // The transfer protocol of the API. // Values MUST be from the list: "http", "https", "ws", "wss". // If the schemes is not included, the default scheme to be used is the one used to access the Swagger definition itself. // SL: only "https" supported right now. Schemes []string `json:"schemes,omitempty"` // A list of MIME types the APIs can consume. // This is global to all APIs but can be overridden on specific API calls. // Value MUST be as described under Mime Types. Consumes []string `json:"consumes,omitempty"` // A list of MIME types the APIs can produce. // This is global to all APIs but can be overridden on specific API calls. // Value MUST be as described under Mime Types. Produces []string `json:"produces,omitempty"` // The available paths and operations for the API. Paths map[string]SwaggerPathT `json:"paths"` // An object to hold data types produced and consumed by operations. Definitions map[string]SwaggerSchemaT `json:"definitions,omitempty"` // An object to hold parameters that can be used across operations. // This property does not define global parameters for all operations. Parameters []SwaggerParameterT `json:"parameters,omitempty"` // An object to hold responses that can be used across operations. // This property does not define global responses for all operations. Responses map[string]SwaggerResponseT `json:"responses,omitempty"` // Security scheme definitions that can be used across the specification. SecurityDefinitions map[string]SwaggerSecDefsT `json:"securityDefinitions,omitempty"` // A declaration of which security schemes are applied for the API as a whole. // The list of values describes alternative security schemes that can be used (that is, there is a logical OR between the security requirements). // Individual operations can override this definition. Security []SwaggerSecurityT `json:"security,omitempty"` // A list of tags used by the specification with additional metadata. // The order of the tags can be used to reflect on their order by the parsing tools. // Not all tags that are used by the Operation Object must be declared. // The tags that are not declared may be organized randomly or based on the tools' logic. // Each tag name in the list MUST be unique. Tags []SwaggerTagT `json:"tags,omitempty"` // Additional external documentation. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` }
All the fields comments are copied from swagger specification at http://swagger.io/specification/ Stonelizard is not entirely compliant with the specification right now. We tried to add notes (preceded by the 'SL:' notation) pointing the differences, but it is possible that we have missed some details here or there.
type SwaggerTagT ¶
type SwaggerTagT struct { // Required. The name of the tag. Name string `json:"name"` // A short description for the tag. GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this tag. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` }
type SwaggerWSEventT ¶
type SwaggerWSEventT struct { // A list of tags for API documentation control. // Tags can be used for logical grouping of operations by resources or any other qualifier. Tags []string `json:"tags,omitempty"` // A short summary of when the event fires. // For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters. Summary string `json:"summary,omitempty"` // A verbose explanation of the event behavior. GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this event. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` // Required. Unique string used to identify the websocket event. // The operation id combined with the event id MUST be unique among // all operations+events described in the API. Tools and libraries MAY use the // operationId/eventId combination to uniquely identify a websocket // event, therefore, it is recommended to follow common programming naming // conventions. EventId string `json:"eventId"` // A list of parameters that are applicable for this websocket event. // The list MUST NOT include duplicated parameters. Parameters []SwaggerEventParameterT `json:"parameters,omitempty"` // Declares this event to be deprecated. // Usage of the declared event should be refrained. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` // A declaration of which security schemes are applied for this operation. // The list of values describes alternative security schemes that can be used // (that is, there is a logical OR between the security requirements). // This definition overrides any declared top-level security. // To remove a top-level security declaration, an empty array can be used. Security map[string]SwaggerSecurityT `json:"security,omitempty"` }
type SwaggerWSOperationT ¶
type SwaggerWSOperationT struct { // A list of tags for API documentation control. // Tags can be used for logical grouping of operations by resources or any other qualifier. Tags []string `json:"tags,omitempty"` // A short summary of what the operation does. // For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters. Summary string `json:"summary,omitempty"` // A verbose explanation of the operation behavior. GFM syntax can be used for rich text representation. Description string `json:"description,omitempty"` // Additional external documentation for this operation. ExternalDocs *SwaggerExternalDocsT `json:"externalDocs,omitempty"` // Required. Unique string used to identify the websocket suboperation. // The operation id combined with the suboperation id MUST be unique among // all operations described in the API. Tools and libraries MAY use the // operationId/suboperationId combination to uniquely identify a websocket // suboperation, therefore, it is recommended to follow common programming naming // conventions. SuboperationId string `json:"suboperationId"` // A list of parameters that are applicable for this websocket suboperation. // The list MUST NOT include duplicated parameters. Parameters []SwaggerParameterT `json:"parameters,omitempty"` // Required. The list of possible responses as they are returned from executing this operation. Responses map[string]SwaggerResponseT `json:"responses"` // Declares this operation to be deprecated. // Usage of the declared operation should be refrained. // Default value is false. Deprecated bool `json:"deprecated,omitempty"` // A declaration of which security schemes are applied for this operation. // The list of values describes alternative security schemes that can be used // (that is, there is a logical OR between the security requirements). // This definition overrides any declared top-level security. // To remove a top-level security declaration, an empty array can be used. Security map[string]SwaggerSecurityT `json:"security,omitempty"` }
func GetWebSocketSpec ¶
func GetWebSocketSpec(field reflect.StructField, WSMethodName string, WSMethod reflect.Method) (*SwaggerWSOperationT, error)
Returns de websocket swagger specification
type SwaggerXmlT ¶
type SwaggerXmlT struct { // Replaces the name of the element/attribute used for the described schema property. // When defined within the Items Object (items), it will affect the name of the individual XML elements within the list. // When defined alongside type being array (outside the items), it will affect the wrapping element and only if wrapped is true. // If wrapped is false, it will be ignored. Name string `json:"name,omitempty"` // The URL of the namespace definition. Value SHOULD be in the form of a URL. Namespace string `json:"namespace,omitempty"` // The prefix to be used for the name. Prefix string `json:"prefix,omitempty"` // Declares whether the property definition translates to an attribute instead of an element. // Default value is false. Attribute bool `json:"attribute,omitempty"` // MAY be used only for an array definition. // Signifies whether the array is wrapped (for example, <books><book/><book/></books>) or unwrapped (<book/><book/>). // Default value is false. The definition takes effect only when defined alongside type being array (outside the items). Wrapped bool `json:"wrapped,omitempty"` }
type Unmarshaler ¶
type Unmarshaler interface {
Decode(v interface{}) error
}
type UrlNode ¶
type UrlNode struct { Path string // The URL path with input parameters Proto []string // Valid protocols: http, https, ws, wss Headers []string // List of HTTP header parameters required by the operation for input Query []string // List of query parameters required by the operation for input Body []string // List of HTTP body parameters required by the operation for input ParmNames []string // Complete list of parameter names (from path, headers, query and body) Handle HandleHttpFn WSocketOperations *strtree.Node // If this.Proto contains ws | wss, then store here the suboperations defined by the methods of the type returned by the main handlers WSocketEvents *strtree.Node // If this.Proto contains ws | wss, then store here the events defined by the event fields of the type returned by the main handlers // contains filtered or unexported fields }
type WSEventTrigger ¶
type WSEventTrigger struct { EventData chan interface{} Status bool }
func NewWSEventTrigger ¶
func NewWSEventTrigger() *WSEventTrigger
Initializes a websocket event trigger
func (*WSEventTrigger) Trigger ¶
func (wset *WSEventTrigger) Trigger(data ...interface{}) (err error)
Call this method from your websocket to trigger an event all parameters data will be sent through the websocket to the client. The data parameters MUST be compliant (length and types) to what you defined in the StructTag for your particular event.
type WSocketEventRegistry ¶
Source Files ¶
- Base64Unmarshaler.Decode.go
- DummyUnmarshaler.Decode.go
- FileServerHandlerT.ServeHTTP.go
- GetMethodInfo.go
- GetSwaggerType.go
- GetWebSocketEventSpec.go
- GetWebSocketSpec.go
- MultipartUnmarshaler.Decode.go
- MultipartUnmarshaler.More.go
- New.go
- NewBase64Unmarshaler.go
- NewDummyUnmarshaler.go
- NewListener.go
- NewMultipartUnmarshaler.go
- NewReadCloser.go
- NewStaticBase64Encoder.go
- NewStaticEncoder.go
- NewWSEventTrigger.go
- NewWithPKI.go
- ParseFieldList.go
- PublicAccessT.go
- SLFileSystem.go
- Service.Close.go
- Service.FetchEndpointHandler.go
- Service.ListenAndServeTLS.go
- Service.ServeHTTP.go
- Service.String.go
- ServiceWithPKI.ListenAndServeTLS.go
- ServiceWithPKI.ServeHTTP.go
- Static.Encode.go
- StaticBase64.Encode.go
- StoppableListener.Accept.go
- StoppableListener.Stop.go
- UrlNode.String.go
- WSEventTrigger.Trigger.go
- buildHandle.go
- buildSubHandles.go
- defs-swagger.go
- defs.go
- doc.go
- f64Conv.go
- getResponses.go
- getWebSocketOps.go
- init.go
- initSvc.go
- isZero.go
- pushParms.go
- setIndirect.go
- validateProtoList.go
- wsEventHandle.go