server

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 10 Imported by: 0

README

serverlib

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server represents an HTTP server with routing and session management capabilities. It includes an HTTP server, a router for handling HTTP requests, a session manager for managing user sessions, a session key for session security, and a template engine for rendering HTML templates.

var ServerInstance *Server

ServerInstance represents the singleton instance of the server.

func NewServer

func NewServer(config ...ServerConfig) *Server

NewServer creates a new instance of Server with the provided configuration. If no configuration is provided, it uses default settings with an address of ":8080" and a new ServeMux as the handler.

Parameters:

  • config: Optional variadic parameter of type ServerConfig. If provided, the first element is used as the server configuration.

Returns:

  • *Server: A pointer to the newly created Server instance.

func (*Server) AddTemplateSource

func (s *Server) AddTemplateSource(source string)

AddTemplateSource adds a new template source to the server's template manager. The source parameter specifies the template source path to be added.

func (*Server) GetSession

func (s *Server) GetSession(w http.ResponseWriter, r *http.Request) (sessions.Session, bool)

GetSession retrieves the session associated with the request's cookie. If the session does not exist, a new session is created and a new cookie is set.

Parameters:

  • w: The HTTP response writer.
  • r: The HTTP request.

Returns:

  • sessions.Session: The session associated with the request.
  • bool: A boolean indicating whether the session was retrieved (true) or newly created (false).

func (*Server) Handle

func (s *Server) Handle(pattern string, handler http.Handler)

Handle registers a handler to handle HTTP requests with the given pattern.

func (*Server) HandleFunc

func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))

HandleFunc registers a function to handle HTTP requests with the given pattern.

func (*Server) Render

func (s *Server) Render(w io.Writer, template string, data map[string]interface{})

Render renders the specified template with the given data and writes the result to the response writer.

func (*Server) SessionKey

func (s *Server) SessionKey() string

SessionKey returns the session key associated with the server instance. This key is used to identify and manage user sessions.

func (*Server) Sessions

func (s *Server) Sessions() sessions.Sessions

Sessions returns the session manager associated with the server instance. It provides access to the session management functionalities.

func (*Server) Start

func (s *Server) Start() error

Start starts the server.

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server.

func (*Server) Templates

func (s *Server) Templates() *templates.Templates

Templates returns the server's templates. It provides access to the templates associated with the server instance.

type ServerConfig

type ServerConfig struct {
	Address                      string
	Handler                      http.Handler
	DisableGeneralOptionsHandler bool
	TLSConfig                    *tls.Config
	ReadTimeout                  time.Duration
	ReadHeaderTimeout            time.Duration
	WriteTimeout                 time.Duration
	IdleTimeout                  time.Duration
	MaxHeaderBytes               int
	ConnState                    func(net.Conn, http.ConnState)
	ErrorLog                     *log.Logger
	BaseContext                  func(net.Listener) context.Context
	ConnContext                  func(ctx context.Context, c net.Conn) context.Context
	SessionManager               sessions.Sessions
	SessionKey                   string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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