Documentation
¶
Overview ¶
This package provides a way to set the context of a web application by serving an 'index.html' file with the
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleContext ¶
HandleContext is a handler for the web app context. Use it in the http server to return the resource specified in index.html
Example ¶
If index.html contains the following:
... <head> ... <script src="context.js"></script> ... </head>
then provide a http request handler like
http.HandleFunc("/context.js", webappcontext.HandleContext(func(r *http.Request)(webappcontext.Context) { return webappcontext.Context { Networking: webappcontext.Networking { BaseUrl : "http://www.mysite.com", APIUrls: {"API", "http://api.mysite.com"}, } } }))
func HandleContextStatic ¶
func HandleContextStatic(baseURL, apiURL, gqlURL, websocketURL string, authenticationEnabled bool) http.HandlerFunc
HandleContextStatic creates a handler for a static context providing the following endpoints: API, ws, GraphQL
Types ¶
type AuthenticationContext ¶
type AuthenticationContext struct {
AuthenticationRequired bool `json:"authentication_required,omitempty"`
}
AuthenticationContext provides information about wether authentication is enabled for the application.
type Context ¶
type Context struct { Networking NetworkingContext `json:"networking,omitempty"` Authentication AuthenticationContext `json:"authentication,omitempty"` }
Context is the context we can provide to the web application. It consists of information about endpoints and if authentication is enabled.
type ContextProvider ¶
ContextProvider is a provider of contexts. It can use the request to determine the context to return.
type NetworkingContext ¶
type NetworkingContext struct { BaseURL string `json:"base_url,omitempty"` APIUrls map[string]string `json:"api_urls,omitempty"` WebsocketEndpoints map[string][]string `json:"websocket_endpoints,omitempty"` GraphQLEndpoints map[string][]string `json:"gql_endpoints,omitempty"` }
NetworkingContext provides information regarding different named endpoints for REST, GraphQL and Websockets. It also provides the BaseURL of the application.