webappcontext

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 4 Imported by: 0

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

func HandleContext(ctxtProvider func(*http.Request) (Context, error)) http.HandlerFunc

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

type ContextProvider interface {
	Context(*http.Request) (Context, error)
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL