http

package
v0.0.0-...-375f364 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const ServerShutdownTime = 3 * time.Second

ServerShutdownTime is the time the server allows processes to finish before shuting down.

Variables

View Source
var ReposEndpoint string = "https://api.github.com/users/Lambels/repos"

ReposEndpoint represents the endpoint to get repos for projects state, configurable for tests.

Functions

func LogError

func LogError(r *http.Request, err error)

LogError logs an error with format '[HTTP] error: {method} {path}: {error message}'

func RunDebugServer

func RunDebugServer() error

RunDebugServer runs a debug server on port 8000 blocking function.

func SendError

func SendError(w http.ResponseWriter, r *http.Request, err error)

SendError sends an error over http. maps system error codes to http error codes.

func SendJSON

func SendJSON(w io.Writer, data interface{}) error

SendJSON sends json: data over http.

Types

type Server

type Server struct {

	// server address.
	Addr   string
	Domain string

	// Services used by the http package.
	AuthService         pa.AuthService
	UserService         pa.UserService
	BlogService         pa.BlogService
	SubBlogService      pa.SubBlogService
	CommentService      pa.CommentService
	EventService        pa.EventService
	SubscriptionService pa.SubscriptionService
	EmailService        pa.EmailService
	ProjectService      pa.ProjectService
	ProjectsFileSystem  pa.FileService
	BlogsFileSystem     pa.FileService
	// contains filtered or unexported fields
}

Server represents a backend api HTTP service which wraps all our HTTP functionality.

func NewServer

func NewServer(conf *pa.Config) *Server

NewServer registers all routes and returns a new server with the conf configurations.

func (*Server) Close

func (s *Server) Close() error

Close brings the server to a gracefull shutdown and stops the cron job.

func (*Server) HandleCommentEvent

func (s *Server) HandleCommentEvent(ctx context.Context, hand pa.SubscriptionService, event pa.Event) error

HandleCommentEvent handels the pa.EventTopicNewComment -> ./event.go. sends an email to all subscribers.

func (*Server) HandleSubBlogEvent

func (s *Server) HandleSubBlogEvent(ctx context.Context, hand pa.SubscriptionService, event pa.Event) error

HandleSubBlogtEvent handels the pa.EventTopicNewSubBlog -> ./event.go. sends an email to all subscribers.

func (*Server) NewOAuthConfig

func (s *Server) NewOAuthConfig(source string) *oauth2.Config

NewOAuthConfig returns an oauth2.0 config object to start the oauth2.0 authorization flow. source determines the provider config. returns an empty config if not found but that should never happen.

func (*Server) Open

func (s *Server) Open() error

Open validates the configurration and starts the server on the address.

func (*Server) RegisterCronJon

func (s *Server) RegisterCronJon(spec string, cmd func()) error

RegisterCronJob registers a new job to s.cron, can be call regardless if cron is or isnt running.

func (*Server) UseTLS

func (s *Server) UseTLS() bool

UseTLS retruns true if cert + key file found.

Jump to

Keyboard shortcuts

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