web

package
v0.0.9-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package web implements a web server that provides a front-end for the go-pb application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PageData

type PageData struct {
	Title        string
	Brand        string
	Tagline      string
	Theme        string
	ID           string
	User         token.User
	Pastes       []store.Paste
	Paste        store.Paste
	Server       string
	Version      string
	ErrorCode    int
	ErrorText    string
	ErrorMessage string
	PastesCount  int64
	UsersCount   int64
}

PageData contains the data that any page template may need.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server encapsulates a router and a server. Normally, you'd create a new instance by calling New which configures the rotuer and then call ListenAndServe to start serving incoming requests.

func New

func New(l *lgr.Logger, opts ServerOptions) *Server

New returns an instance of the WebServer with initialised middleware, loaded templates and routes. You can call ListenAndServe on a newly created instance to initialise the HTTP server and start handling incoming requests.

func (*Server) ListenAndServe

func (h *Server) ListenAndServe() error

ListenAndServe starts an HTTP server and binds it to the provided address. You have to call New() first to initialise the WebServer.

func (*Server) Shutdown

func (h *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shutdown the server with the givem context.

type ServerOptions

type ServerOptions struct {
	Addr               string        // address to listen on, see http.Server docs for details
	Proto              string        // protocol, either "http" or "https"
	ReadTimeout        time.Duration // maximum duration for reading the entire request.
	WriteTimeout       time.Duration // maximum duration before timing out writes of the response
	IdleTimeout        time.Duration // maximum amount of time to wait for the next request
	LogFile            string        // if not empty, will write logs to the file
	LogMode            string        // can be either "debug" or "production"
	BrandName          string        // displayed at the top of each page, default is "Go PB"
	BrandTagline       string        // displayed below the BrandName
	Assets             string        // location of the assets folder (css, js, images)
	Templates          string        // location of the templates folder
	MaxBodySize        int64         // maximum size for request's body
	BootstrapTheme     string        // one of the themes, see css files in the assets folder
	Version            string        // app version, comes from build
	AuthSecret         string        // secret for JWT token generation and validation
	AuthTokenDuration  time.Duration // JWT token expiration duration
	AuthCookieDuration time.Duration // cookie expiration time
	AuthIssuer         string        // application name used as an issuer in oauth requests
	AuthURL            string        // callback URL for oauth requests
	DBType             string        // type of the store to use
	DBConn             string        // database connection string
	GitHubCID          string        // github client id for oauth
	GitHubCSEC         string        // github client secret for oauth
	GoogleCID          string        // google client id for oauth
	GoogleCSEC         string        // google client secret for oauth
	TwitterCID         string        // twitter client id for oauth
	TwitterCSEC        string        // twitter client secret for oauth
}

ServerOptions defines various parameters needed to run the WebServer

Jump to

Keyboard shortcuts

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