Documentation ¶
Index ¶
- func GetSession(w http.ResponseWriter, r *http.Request) (sessions.Session, bool)
- func LogDebug(message string, value string)
- func LogError(message string, value string)
- func LogInfo(message string, value string)
- type LogLevel
- type Server
- func (s *Server) AddTemplateSource(source string)
- func (s *Server) GetSession(w http.ResponseWriter, r *http.Request) (sessions.Session, bool)
- func (s *Server) Handle(pattern string, handler http.Handler)
- func (s *Server) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
- func (s *Server) Render(w io.Writer, template string, data map[string]interface{})
- func (s *Server) SessionKey() string
- func (s *Server) Sessions() sessions.Sessions
- func (s *Server) SetLogLevel(level LogLevel)
- func (s *Server) Start() error
- func (s *Server) Stop() error
- func (s *Server) Templates() *templates.Templates
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetSession ¶ added in v0.0.4
GetSession retrieves the session associated with the request's cookie. shorthand for ServerInstance.GetSession(w, r)
func LogDebug ¶
LogDebug logs a debug message if the server's log level is set to Debug or higher. It takes two parameters: - message: A string representing the debug message. - value: A string representing additional information to log with the message.
func LogError ¶
LogError logs an error message with a specified value if the server's log level is set to Error or higher. Parameters:
- message: A string representing the error message to be logged.
- value: A string representing additional information or context about the error.
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 ¶
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 ¶
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) HandleFunc ¶
HandleFunc registers a function to handle HTTP requests with the given pattern.
func (*Server) Render ¶
Render renders the specified template with the given data and writes the result to the response writer.
func (*Server) SessionKey ¶
SessionKey returns the session key associated with the server instance. This key is used to identify and manage user sessions.
func (*Server) Sessions ¶
SessionManager returns the server's session manager. It provides access to the session manager associated with the server instance.
func (*Server) SetLogLevel ¶
SetLogLevel sets the logging level for the server.
Parameters:
level (LogLevel): The desired logging level.
Usage:
server.SetLogLevel(LogLevelDebug)
type ServerConfig ¶
type ServerConfig struct { Address string 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 DateFormat func(time.Time) string LogLevel LogLevel }