balda

package module
v0.0.0-...-12c3517 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2021 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host         string
	Port         int
	ReuseConn    bool
	MaxReuseConn int
	Cache        bool
	CacheMaxAge  int
}

Config type

type Cookie struct {
	Name     string
	Value    string
	Path     string
	Domain   string
	Expires  time.Time
	MaxAge   string
	Secure   bool
	HTTPOnly bool
}

Cookie type

func (*Cookie) String

func (c *Cookie) String() string

Cookie.String() returns a string, put it to Set-Cookie header

type Request

type Request struct {
	Type    string
	Path    string
	Proto   string
	Headers map[string]string
	Body    map[string]string
	Params  map[interface{}]interface{}
	Static  bool
}

Request type

type Response

type Response struct {
	Proto      string
	Statuscode int
	Statusmsg  string
	Headers    map[string]string

	status.Status
	// contains filtered or unexported fields
}

Response type

func (*Response) DelCookie

func (res *Response) DelCookie(name string)

DelCookie (name string) immediately deletes cookie

func (*Response) Error

func (res *Response) Error(status [3]string)

Error (status []string) sends response with error to client

func (*Response) Header

func (res *Response) Header(key string, value string)

Header (key string, value string) sets header with given name and value

func (*Response) Redirect

func (res *Response) Redirect(to string)

Redirect (to string) redirect user to given path

func (*Response) Send

func (res *Response) Send(body string)

Send (body string) sends data to client

func (*Response) SendFile

func (res *Response) SendFile(path string) error

SendFile (path string) (error) sends file to client

func (*Response) SetCookie

func (res *Response) SetCookie(c Cookie)

SetCookie (c *Cookie) sets cookie, it takes data from cookie object

type Server

type Server struct {
	Host       string
	Port       int
	Socket     net.Listener
	STATIC     []staticRoute
	Middleware []handler
	GET        []route
	POST       []route
	FileCache  hmap.HashMap
	Config     Config
}

Server type

func Express

func Express(cfg Config) Server

Express (cfg *Config) (Server) returns a Server object

func (*Server) Get

func (s *Server) Get(path string, handler func(req *Request, res *Response))

Get (path string, handler func(req *Request, res *Response)) appends given handler to GET routes

func (*Server) Listen

func (s *Server) Listen() error

Listen () (error) listens for connections

func (*Server) ListenTLS

func (s *Server) ListenTLS(certificate string, key string) error

ListenTLS (certificate string, key string) listens for connections, and process it with tls

func (*Server) Post

func (s *Server) Post(path string, handler func(req *Request, res *Response))

Post (path string, handler func(req *Request, res *Response)) appends given handler to POST routes

func (*Server) Static

func (s *Server) Static(path string, realPath string)

Static (path string, realPath string) serves static files

func (*Server) Use

func (s *Server) Use(middleware handler)

Use (middleware func(req *Request, res *Response)) appends given middleware to server

Jump to

Keyboard shortcuts

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