server

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APISPAServer

type APISPAServer struct {
	Router mux.Router
	// contains filtered or unexported fields
}

APISPAServer is a representation of a basic server that serves a single page application (SPA) and an application programming interface (API).

The server is created by calling e.g.:

s := NewAPISPAServer("8080")

After which, API routes can be registered on the server's router:

r := &server.Router
r.HandleFunc("/api/v1/status", getStatus).Methods("GET")

By default, the SPA is served from:

`./public/index.html`

The SPA directory can be changed by calling:

server.SetSPA("public/service-xy")

This will then serve:

`./public/service-xy/index.html`

Finally, the server can be started:

log.Fatal(server.ListenAndServe())

func NewAPISPAServer

func NewAPISPAServer(port string) *APISPAServer

NewAPISPAServer returns a new server instance.

By default it will serve:

`./public/index.html`

for the single page application.

func (*APISPAServer) ListenAndServe

func (server *APISPAServer) ListenAndServe() error

Start the server and listen to requests on the specified port.

func (*APISPAServer) SetSPA

func (server *APISPAServer) SetSPA(path string)

Set the path to the single page application.

The path passed should point to the directory where `index.html` lies, though without tailing slash:

srv.SetSPA("public/admin")

func (*APISPAServer) Shutdown

func (server *APISPAServer) Shutdown()

Shut down server gracefully.

Jump to

Keyboard shortcuts

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