httpjson

package
v0.0.0-...-d36796e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package httpjson provides utilities to handle Shana-opinioned HTTP JSON requests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	IP        string `shana:"ip"`   // The IP to bind. If it's not set, all IPs are bound.
	Port      int    `shana:"port"` // The port to listen.
	PkgPrefix string `shana:"-"`    // Filter all exported routes by package prefix.
}

Config for http server.

func (*Config) Init

func (c *Config) Init(ctx context.Context)

Init initializes the config and fills zero values with defaults.

func (*Config) Validate

func (c *Config) Validate(ctx context.Context)

Validate validates the config.

type DebugInfo

type DebugInfo struct {
	FuncName string   `json:"funcName,omitempty"`
	Errors   []string `json:"errors,omitempty"`
}

DebugInfo contains more debug information.

type Response

type Response struct {
	Code    any        `json:"code,omitempty"`
	Message string     `json:"message,omitempty"`
	Error   string     `json:"error,omitempty"`
	Debug   *DebugInfo `json:"_debug,omitempty"` // Only valid when debug is enabled.
	Data    any        `json:"data,omitempty"`
}

Response is the Shana-opinioned HTTP JSON protocol response.

type Router

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

Router is a HTTP JSON router.

func NewRouter

func NewRouter(config *Config) *Router

NewRouter creates a new HTTP JSON router.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)

ServeHTTP implements http.Handler.

type Server

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

Server is a HTTP JSON server.

func NewServer

func NewServer(config *Config) *Server

NewServer creates a new HTTP JSON server.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

Serve starts the server.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown stops the server.

Jump to

Keyboard shortcuts

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