{"modulePath":"github.com/CaliLuke/loom","version":"v1.12.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package example\n\nPackage example contains code generation algorithms to produce an example server and client implementation for the transports defined in the design.\n\n## Functions\n\n```go\nfunc CLIFiles(genpkg string, root *expr.RootExpr) []*codegen.File\n```\nCLIFiles returns example client tool main implementation for each server expression in the design.\n\n```go\nfunc ServerFiles(genpkg string, root *expr.RootExpr, services *service.ServicesData) []*codegen.File\n```\nServerFiles returns an example server main implementation for every server expression in the service design.\n\n## Types\n\n```go\ntype Data struct {\n\t// Name is the server name.\n\tName string\n\t// Description is the server description.\n\tDescription string\n\t// Services is the list of services supported by the server.\n\tServices []string\n\t// Schemes is the list of supported schemes by the server.\n\tSchemes []string\n\t// Hosts is the list of hosts defined in the server.\n\tHosts []*HostData\n\t// Variables is the list of URL parameters defined in every host.\n\tVariables []*VariableData\n\t// Transports is the list of transports defined in the server.\n\tTransports []*TransportData\n\t// JSONRPCServices is the list of services hosted by the server that\n\t// define a JSON-RPC transport, in server order.\n\tJSONRPCServices []string\n\t// Dir is the directory name for the generated client and server examples.\n\tDir string\n\t// HTTPHandlerArgs are the ordered arguments that follow the context and\n\t// URL in the example handleHTTPServer function. Every HTTP URI passes\n\t// these arguments, so generators that declare the function use them to\n\t// keep its signature in step with the call in the example main.\n\tHTTPHandlerArgs []HandlerArg\n}\n```\nData contains the data about a single server.\n\n```go\nfunc (s *Data) AvailableHosts() []string\n```\nAvailableHosts returns a list of available host names.\n\n```go\nfunc (s *Data) DefaultHost() *HostData\n```\nDefaultHost returns the first host defined in the server expression.\n\n```go\nfunc (s *Data) DefaultTransport() *TransportData\n```\nDefaultTransport returns the default transport for the given server. If multiple transports are defined, HTTP transport is used as the default.\n\n```go\nfunc (s *Data) HasTransport(transport Transport) bool\n```\nHasTransport checks if the server supports the given transport.\n\n```go\nfunc (s *Data) HostsGRPC() bool\n```\nHostsGRPC reports whether the server hosts a service that defines a gRPC transport. The example generators emit the gRPC server and client files of a server only when it does.\n\n```go\nfunc (s *Data) HostsHTTP() bool\n```\nHostsHTTP reports whether the server hosts a service that defines an HTTP transport. The example generators emit the HTTP server and client files of a server only when it does.\n\n```go\nfunc (s *Data) HostsJSONRPC() bool\n```\nHostsJSONRPC reports whether the server hosts a service that defines a JSON-RPC transport. The example generators emit the JSON-RPC server and client files of a server only when it does.\n\n```go\ntype HandlerArg struct {\n\t// ServiceName is the design name of the service the argument belongs to.\n\tServiceName string\n\t// Endpoint is the name of the variable that holds the service endpoints.\n\tEndpoint string\n\t// Service is the name of the variable that holds the service\n\t// implementation.\n\tService string\n}\n```\nHandlerArg represents one argument slot to the handler call in the example server. Only one of Endpoint or Service may be set for each entry.\n\n```go\ntype HostData struct {\n\t// Name is the host name.\n\tName string\n\t// Description is the host description.\n\tDescription string\n\t// Schemes is the list of schemes supported by the host. It is computed\n\t// from the URI expressions defined in the Host.\n\t// Possible values are http, https, grpc, grpcs.\n\tSchemes []string\n\t// URIs is the list of URLs defined in the host.\n\tURIs []*URIData\n\t// Variables is the list of URL parameters.\n\tVariables []*VariableData\n}\n```\nHostData contains the data about a single host in a server.\n\n```go\nfunc (h *HostData) DefaultURL(transport Transport) string\n```\nDefaultURL returns the first URL defined for the given transport in a host.\n\n```go\ntype ServersData map[string]*Data\n```\nServersData holds the server data from the service design indexed by server name.\n\n```go\nfunc NewServersData() ServersData\n```\nNewServersData creates a fresh per-generation server cache.\n\n```go\nfunc (d ServersData) Get(svr *expr.ServerExpr, root *expr.RootExpr) *Data\n```\nGet returns the server data for the given server expression. It builds the server data if the server name does not exist in the map.\n\n```go\ntype Transport string\n```\nTransport is a type for supported Loom transports.\n\n```go\nconst (\n\t// TransportHTTP is the HTTP transport.\n\tTransportHTTP Transport = \"http\"\n\t// TransportGRPC is the gRPC transport.\n\tTransportGRPC = \"grpc\"\n)\n```\n\n```go\ntype TransportData struct {\n\t// Type is the transport type.\n\tType Transport\n\t// Name is the transport name.\n\tName string\n\t// Services is the list of services supported by the transport.\n\tServices []string\n}\n```\nTransportData contains the data about a transport (http or grpc).\n\n```go\ntype URIData struct {\n\t// URL is the underlying URL.\n\tURL string\n\t// Scheme is the URL scheme.\n\tScheme string\n\t// Port is the default port for the scheme.\n\t// http - 80, https - 443, grpc - 8080, grpcs - 8443\n\tPort string\n\t// Transport is the transport type for the URL.\n\tTransport *TransportData\n\t// HandlerArgs are the precomputed handler arguments for this URI used by\n\t// the example server template. Each entry may contain an Endpoint and/or\n\t// Service argument name to be passed to the handler in order.\n\tHandlerArgs []HandlerArg\n}\n```\nURIData contains the data about a URL.\n\n```go\ntype VariableData struct {\n\t// Name is the name of the variable.\n\tName string\n\t// Description is the variable description.\n\tDescription string\n\t// VarName is the variable name used in generating flag variables.\n\tVarName string\n\t// DefaultValue is the default value for the variable. It is set to the\n\t// default value defined in the variable attribute if exists, or else set\n\t// to the first value in the enum expression.\n\tDefaultValue string\n\t// Values is the list of allowed values for the variable. The values can\n\t// only be primitives. We convert the primitives into string type so that\n\t// we could use them to replace the URL variables in the example\n\t// generation.\n\tValues []string\n}\n```\nVariableData contains the data about a URL variable.\n\n","path":"github.com/CaliLuke/loom/codegen/example","name":"example","synopsis":"Package example contains code generation algorithms to produce an example server and client implementation for the transports defined in the design.","isRedistributable":true}
