proto

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

README

go-http.v2

Coverage Status Release Go Report Card Build Status

Install

go get -u github.com/deweppro/go-http/v2

Example

Documentation

Index

Constants

View Source
const (
	VersionKey = `Accept`

	UUIDKey       = `X-Request-ID`
	StatusCodeKey = `X-Status`

	SignKey = `Signature`

	ContentTypeKey         = `Content-Type`
	ContentTypeJSONValue   = `application/json; charset=utf-8`
	ContentTypeBinaryValue = `application/octet-stream`

	StatusCodeFail         uint = 0
	StatusCodeOK           uint = 1
	StatusCodeNotFound     uint = 2
	StatusCodeUnauthorized uint = 3
	StatusCodeForbidden    uint = 4
	StatusCodeServerError  uint = 5
)

Variables

View Source
var (
	ErrServAlreadyRunning = errors.New("server is already running")
	ErrEpollEmptyEvents   = errors.New("epoll events is empty")
	ErrInvalidSignature   = errors.New(`invalid signature format`)
	ErrEmptyPool          = errors.New(`pool is empty`)
	ErrClientNotFound     = errors.New(`client not found`)
)

Functions

func Code2HTTPCode

func Code2HTTPCode(v uint) int

func CreateUUID added in v2.0.2

func CreateUUID() string

func GetFD

func GetFD(c net.Conn) int

func HTTPCode2Code

func HTTPCode2Code(v int) uint

func RandomPort

func RandomPort(host string) (string, error)

func Reader

func Reader(rc io.ReadCloser) ([]byte, error)

Types

type CliCaller

type CliCaller func(pool Pooler, in *Request, out *Response) error

type Client

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

func NewClient

func NewClient(conf Configer) *Client

func (*Client) Call

func (o *Client) Call(name string, in *Request, out *Response) error

func (*Client) Client

func (o *Client) Client(name string, call CliCaller)

type Common

type Common struct {
	Meta http.Header
	Body []byte
}

func (*Common) CreateSign

func (o *Common) CreateSign(s *Signer)

func (*Common) DecodeGob

func (o *Common) DecodeGob(v interface{}) error

func (*Common) DecodeJSON

func (o *Common) DecodeJSON(v interface{}) error

func (*Common) EncodeGob

func (o *Common) EncodeGob(v interface{}) (err error)

func (*Common) EncodeJSON

func (o *Common) EncodeJSON(v interface{}) (err error)

func (*Common) GetSignature

func (o *Common) GetSignature() (s Sign, err error)

func (*Common) GetUUID

func (o *Common) GetUUID() string

func (*Common) SetMeta

func (o *Common) SetMeta(m map[string]string)

func (*Common) SetUUID

func (o *Common) SetUUID(v string)

func (*Common) UpdateUUID added in v2.0.2

func (o *Common) UpdateUUID()

type Configer

type Configer interface {
	Get(name string) List
}

type List

type List []string

func (List) Pool

func (v List) Pool() (string, error)

type Pool

type Pool struct {
	Items map[string]List `yaml:"services" json:"services"`
}

func (Pool) Get

func (c Pool) Get(name string) List

type Pooler

type Pooler interface {
	Pool() (string, error)
}

type Request

type Request struct {
	Common
	Path string
}

func NewRequest

func NewRequest() *Request

func (*Request) GetVersion

func (r *Request) GetVersion() uint64

func (*Request) SetVersion

func (r *Request) SetVersion(v uint64)

func (*Request) UpdateFromHTTP

func (r *Request) UpdateFromHTTP(v *http.Request, headers ...string) (err error)

type Response

type Response struct {
	Common
}

func NewResponse

func NewResponse() *Response

func (*Response) GetStatusCode

func (r *Response) GetStatusCode() uint

func (*Response) SetStatusCode

func (r *Response) SetStatusCode(v uint)

func (*Response) UpdateFromHTTP

func (r *Response) UpdateFromHTTP(v *http.Response, headers ...string) (err error)

func (*Response) WriteToHTTP

func (r *Response) WriteToHTTP(w http.ResponseWriter) error

type Server

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

func NewServer

func NewServer() *Server

func (*Server) Call

func (o *Server) Call(in *Request, out *Response)

func (*Server) Handler

func (o *Server) Handler(path string, ver uint64, call SrvCaller)

type Sign

type Sign struct {
	ID        string
	Algorithm string
	Signature string
}

type Signer

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

func NewCustomSigner

func NewCustomSigner(id, secret string, h func() hash.Hash) *Signer

func NewSigner

func NewSigner(id, secret string) *Signer

func (*Signer) Create

func (s *Signer) Create(b []byte) []byte

func (*Signer) CreateString

func (s *Signer) CreateString(b []byte) string

func (*Signer) ID

func (s *Signer) ID() string

func (*Signer) Validate

func (s *Signer) Validate(b []byte, ex string) bool

type SrvCaller

type SrvCaller func(in *Request, out *Response)

Directories

Path Synopsis
clients
example
servers

Jump to

Keyboard shortcuts

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