package module
Version: v0.0.0-...-af38cf8 Latest Latest

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

Go to latest
Published: Nov 17, 2020 License: MIT Imports: 12 Imported by: 0



Pithy is a very very simple and pithy web framework.It is useful for me.




View Source
const (
	LogLevelDebug = iota


View Source
var (
	ErrInvalidServerRouter  = errors.New("Invalid server router")
	ErrInvalidListenAddress = errors.New("Invalid listen address")

constant errors


func Debugf

func Debugf(fmt string, v ...interface{})

func Debugln

func Debugln(v ...interface{})

func Errorf

func Errorf(fmt string, v ...interface{})

func Errorln

func Errorln(v ...interface{})

func Fatalf

func Fatalf(fmt string, v ...interface{})

func Fatalln

func Fatalln(v ...interface{})

func Flush

func Flush()

func Infof

func Infof(fmt string, v ...interface{})

func Infoln

func Infoln(v ...interface{})

func RegisterLogger

func RegisterLogger(logger Logger)

func Warnf

func Warnf(fmt string, v ...interface{})

func Warnln

func Warnln(v ...interface{})


type APIFunc

type APIFunc func(*HTTPContext) *APIResult

type APIResult

type APIResult struct {
	Message    string `json:"message"`
	ResultCode int    `json:"code"`
	// For internal use
	StatusCode int    `json:"-"`
	RawBytes   []byte `json:"-"` // If raw is not nil, directly send raw bytes rather than sending json bytes of the result

APIError holds the error code and error message for responding to request peer

func NewAPIResult

func NewAPIResult(result, status int, msg string) *APIResult

func NewAPIResultFromResultCode

func NewAPIResultFromResultCode(result int, msg string) *APIResult

func (*APIResult) String

func (r *APIResult) String() string

type APIRouter

type APIRouter interface {
	Path() string
	Method() string
	Handler() APIFunc
	Version() bool

APIRouter defines an interface to determine which handler is called by path and method

type HTTPContext

type HTTPContext struct {
	// contains filtered or unexported fields

func (*HTTPContext) GetFormValueInt64

func (c *HTTPContext) GetFormValueInt64(key string, def int64) int64

func (*HTTPContext) GetFormValueString

func (c *HTTPContext) GetFormValueString(key string) string

func (*HTTPContext) GetFormValueStringTrimBlank

func (c *HTTPContext) GetFormValueStringTrimBlank(key string) string

func (*HTTPContext) GetPathVarInt64

func (c *HTTPContext) GetPathVarInt64(key string, def int64) int64

func (*HTTPContext) GetPathVarString

func (c *HTTPContext) GetPathVarString(key string) string

func (*HTTPContext) GetPathVersion

func (c *HTTPContext) GetPathVersion() string

func (*HTTPContext) GetRequest

func (c *HTTPContext) GetRequest() *http.Request

func (*HTTPContext) GetResponseWriter

func (c *HTTPContext) GetResponseWriter() http.ResponseWriter

func (*HTTPContext) ReadBody

func (c *HTTPContext) ReadBody() ([]byte, error)

func (*HTTPContext) UnmarshalJSONFromBody

func (c *HTTPContext) UnmarshalJSONFromBody(i interface{}) error

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields

func NewHTTPServer

func NewHTTPServer(address string) *HTTPServer

func (*HTTPServer) AppendRouters

func (s *HTTPServer) AppendRouters(rts ...APIRouter)

AppendRouters create mux and update handler of server

func (*HTTPServer) EnablePprof

func (s *HTTPServer) EnablePprof()

func (*HTTPServer) GetListener

func (s *HTTPServer) GetListener() net.Listener

GetListener get the listener of the server

func (*HTTPServer) Serve

func (s *HTTPServer) Serve() error

Serve with the speicified address

func (*HTTPServer) SetNotFoundHandler

func (s *HTTPServer) SetNotFoundHandler(h APIFunc)

SetNotFoundHandler -

func (*HTTPServer) Stop

func (s *HTTPServer) Stop()

Stop stops the server

type Logger

type Logger interface {
	Outputln(lv int, v ...interface{})
	Outputf(lv int, fmt string, v ...interface{})

type SwappableHandler

type SwappableHandler struct {
	// contains filtered or unexported fields

SwappableHandler is a http.Handler thats allows you to swap mux during working

func (*SwappableHandler) ServeHTTP

func (h *SwappableHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implement the http.Handler interface

func (*SwappableHandler) Swap

func (h *SwappableHandler) Swap(r *mux.Router)

Swap swaps the router of the handler

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL