api

package
v3.0.0-alpha.0...-b49f957 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: GPL-3.0 Imports: 49 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExpireFilled     = time.Second * 3
	ExpireShortLived = time.Millisecond * 100
	ExpireLongLived  = time.Hour * 3000
)
View Source
const (
	ProblemMimetype    = "application/problem+json; charset=utf-8"
	ProblemNamespace   = "https://github.com/ProtoconNet/mitum-currency/v3/problems"
	DefaultProblemType = "others"
)

Variables

View Source
var (
	DefaultCacheExpire = time.Hour
	SkipCacheError     = util.NewIDError("skip cache")
)
View Source
var (
	HTTP2EncoderHintHeader = http.CanonicalHeaderKey("x-mitum-encoder-hint")
	HALMimetype            = "application/hal+json; charset=utf-8"
	PlainTextMimetype      = "text/plain; charset=utf-8"
	PrometheusTextMimetype = "text/plain; version=0.0.4"
)
View Source
var (
	HandlerPathNodeInfo                   = `/`
	HandlerPathNodeInfoProm               = `/info/prom`
	HandlerPathNodeMetric                 = `/metrics`
	HandlerPathNodeMetricProm             = `/metrics/prom`
	HandlerPathCurrencies                 = `/currency`
	HandlerPathCurrency                   = `/currency/{currency_id:` + types.ReCurrencyID + `}`
	HandlerPathManifests                  = `/block/manifests`
	HandlerPathOperations                 = `/block/operations`
	HandlerPathOperationsByHash           = `/block/operations/facts`
	HandlerPathOperation                  = `/block/operation/{hash:(?i)[0-9a-z][0-9a-z]+}`
	HandlerPathBlockByHeight              = `/block/{height:[0-9]+}`
	HandlerPathBlockByHash                = `/block/{hash:(?i)[0-9a-z][0-9a-z]+}`
	HandlerPathOperationsByHeight         = `/block/{height:[0-9]+}/operations`
	HandlerPathManifestByHeight           = `/block/{height:[0-9]+}/manifest`
	HandlerPathManifestByHash             = `/block/{hash:(?i)[0-9a-z][0-9a-z]+}/manifest`
	HandlerPathAccount                    = `/account/{address:(?i)` + types.REStringAddressString + `}`            // revive:disable-line:line-length-limit
	HandlerPathAccountOperations          = `/account/{address:(?i)` + types.REStringAddressString + `}/operations` // revive:disable-line:line-length-limit
	HandlerPathAccounts                   = `/accounts`
	HandlerPathOperationBuildFactTemplate = `/builder/operation/fact/template/{fact:[\w][\w\-]*}`
	HandlerPathOperationBuildFact         = `/builder/operation/fact`
	HandlerPathOperationBuildSign         = `/builder/operation/sign`
	HandlerPathOperationBuild             = `/builder/operation`
	HandlerPathSend                       = `/builder/send`
	HandlerPathQueueSend                  = `/builder/send/queue`
	HandelrPathEventOperation             = `/event/operation/{hash:(?i)[0-9a-z][0-9a-z]+}`
	HandelrPathEventAccount               = `/event/account/{address:(?i)` + types.REStringAddressString + `}`
	HandlerPathEventContract              = `/event/contract/{address:(?i)` + types.REStringAddressString + `}`
)
View Source
var (
	UnknownProblem     = NewProblem(DefaultProblemType, "unknown problem occurred")
	UnknownProblemJSON []byte
)
View Source
var (
	HandlerPathDIDDesign   = `/did-registry/{contract:(?i)` + types.REStringAddressString + `}`
	HandlerPathDIDData     = `/did-registry/{contract:(?i)` + types.REStringAddressString + `}/did/{method_specific_id:` + types.ReSpecialCh + `}`
	HandlerPathDIDDocument = `/did-registry/{contract:(?i)` + types.REStringAddressString + `}/document`
)
View Source
var (
	BaseHalHint = hint.MustNewHint("mitum-currency-hal-v0.0.1")
)
View Source
var ContextValueDigestNetwork util.ContextKey = "digest_network"
View Source
var GlobalItemsLimit int64 = 10
View Source
var HALJSONConfigDefault = jsoniter.Config{
	EscapeHTML: false,
}.Froze()
View Source
var PNameAPI = ps.Name("api")
View Source
var PNameStartAPI = ps.Name("start_api")
View Source
var (
	ProblemHint = hint.MustNewHint("mitum-currency-problem-v0.0.1")
)

Functions

func AddQueryValue

func AddQueryValue(b, s string) string

func CacheKey

func CacheKey(key string, s ...string) string

func CacheKeyFromRequest

func CacheKeyFromRequest(r *http.Request) string

func CacheKeyPath

func CacheKeyPath(r *http.Request) string

func DefaultItemsLimiter

func DefaultItemsLimiter(string) int64

func HTTP2HandleError

func HTTP2HandleError(w http.ResponseWriter, err error)

func HTTP2NotSupported

func HTTP2NotSupported(w http.ResponseWriter, err error)

func HTTP2ProblemWithError

func HTTP2ProblemWithError(w http.ResponseWriter, err error, status int)

func HTTP2Stream

func HTTP2Stream(enc encoder.Encoder, w http.ResponseWriter, bufsize int, status int) (*jsoniter.Stream, func())

func HTTP2WriteBytes

func HTTP2WriteBytes(w http.ResponseWriter, b []byte, contentType string, status int)

func HTTP2WriteCache

func HTTP2WriteCache(w http.ResponseWriter, key string, expire time.Duration)

func HTTP2WriteHal

func HTTP2WriteHal(enc encoder.Encoder, w http.ResponseWriter, hal Hal, status int)

func HTTP2WriteHalBytes

func HTTP2WriteHalBytes(enc encoder.Encoder, w http.ResponseWriter, b []byte, status int)

func HTTP2WriteProblem

func HTTP2WriteProblem(w http.ResponseWriter, pr Problem, status int)

func HandleAccount

func HandleAccount(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleAccountOperations

func HandleAccountOperations(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleAccounts

func HandleAccounts(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleBlock

func HandleBlock(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleCurrencies

func HandleCurrencies(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleCurrency

func HandleCurrency(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleDIDData

func HandleDIDData(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleDIDDesign

func HandleDIDDesign(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleDIDDocument

func HandleDIDDocument(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleManifestByHash

func HandleManifestByHash(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleManifestByHeight

func HandleManifestByHeight(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleManifests

func HandleManifests(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleNodeInfo

func HandleNodeInfo(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleNodeInfoProm

func HandleNodeInfoProm(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleNodeMetric

func HandleNodeMetric(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleNodeMetricProm

func HandleNodeMetricProm(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleOperation

func HandleOperation(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleOperations

func HandleOperations(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleOperationsByHash

func HandleOperationsByHash(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleOperationsByHeight

func HandleOperationsByHeight(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleQueueSend

func HandleQueueSend(hd *Handlers, w http.ResponseWriter, r *http.Request)

func HandleSend

func HandleSend(hd *Handlers, w http.ResponseWriter, r *http.Request)

func LoadFromCache

func LoadFromCache(cache Cache, key string, w http.ResponseWriter) error

func MakeCacheKey

func MakeCacheKey(key string) string

func NodeInfo

func NodeInfo(client *isaacnetwork.BaseClient, connInfo quicstream.ConnInfo) (*isaacnetwork.NodeInfo, error)

func NodeMetric

func NodeMetric(client *isaacnetwork.BaseClient, connInfo quicstream.ConnInfo) (*isaacnetwork.NodeMetrics, error)

func ParseBoolQuery

func ParseBoolQuery(s string) bool

func ParseCSVStringQuery

func ParseCSVStringQuery(s string) []string

func ParseLimitQuery

func ParseLimitQuery(s string) int64

func ParseRequest

func ParseRequest(_ http.ResponseWriter, r *http.Request, v string) (string, error, int)

func ParseStringQuery

func ParseStringQuery(s string) string

func ProcessAPI

func ProcessAPI(ctx context.Context) (context.Context, error)

func ProcessStartAPI

func ProcessStartAPI(ctx context.Context) (context.Context, error)

func RateLimiter

func RateLimiter(rps int, burst int) func(http.Handler) http.Handler

func ScanCRLF

func ScanCRLF(data []byte, atEOF bool) (int, []byte, error)

func SetHandlers

func SetHandlers(hd *Handlers, digest bool)

func StringBoolQuery

func StringBoolQuery(key string, v bool) string

func StringOffsetQuery

func StringOffsetQuery(offset string) string

func WriteFromCache

func WriteFromCache(b []byte, w http.ResponseWriter) error

Types

type BaseHal

type BaseHal struct {
	hint.BaseHinter
	// contains filtered or unexported fields
}

func NewBaseHal

func NewBaseHal(i interface{}, self HalLink) BaseHal

func NewEmptyHal

func NewEmptyHal() BaseHal

func (BaseHal) AddExtras

func (hal BaseHal) AddExtras(key string, value interface{}) Hal
func (hal BaseHal) AddLink(rel string, link HalLink) Hal

func (BaseHal) Extras

func (hal BaseHal) Extras() map[string]interface{}

func (BaseHal) Interface

func (hal BaseHal) Interface() interface{}
func (hal BaseHal) Links() map[string]HalLink

func (BaseHal) MarshalJSON

func (hal BaseHal) MarshalJSON() ([]byte, error)

func (BaseHal) RawInterface

func (hal BaseHal) RawInterface() []byte

func (BaseHal) Self

func (hal BaseHal) Self() HalLink

func (BaseHal) SetInterface

func (hal BaseHal) SetInterface(i interface{}) Hal

func (BaseHal) SetSelf

func (hal BaseHal) SetSelf(u HalLink) Hal

func (*BaseHal) UnmarshalJSON

func (hal *BaseHal) UnmarshalJSON(b []byte) error

type BaseHalJSONMarshaler

type BaseHalJSONMarshaler struct {
	hint.BaseHinter
	Embedded interface{}            `json:"_embedded,omitempty"`
	Links    map[string]HalLink     `json:"_links,omitempty"`
	Extra    map[string]interface{} `json:"_extra,omitempty"`
}

type BaseHalJSONUnpacker

type BaseHalJSONUnpacker struct {
	Embedded json.RawMessage        `json:"_embedded,omitempty"`
	Links    map[string]HalLink     `json:"_links,omitempty"`
	Extra    map[string]interface{} `json:"_extra,omitempty"`
}

type Cache

type Cache interface {
	Get(string) ([]byte, error)
	Set(string, []byte, time.Duration) error
}

func NewCacheFromURI

func NewCacheFromURI(uri string) (Cache, error)

type CacheResponseWriter

type CacheResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewCacheResponseWriter

func NewCacheResponseWriter(cache Cache, w http.ResponseWriter, r *http.Request) *CacheResponseWriter

func (*CacheResponseWriter) Cache

func (cr *CacheResponseWriter) Cache() error

func (*CacheResponseWriter) Expire

func (cr *CacheResponseWriter) Expire() time.Duration

func (*CacheResponseWriter) Key

func (cr *CacheResponseWriter) Key() string

func (*CacheResponseWriter) OK

func (cr *CacheResponseWriter) OK() bool

func (*CacheResponseWriter) SetExpire

func (cr *CacheResponseWriter) SetExpire(expire time.Duration) *CacheResponseWriter

func (*CacheResponseWriter) SetKey

func (*CacheResponseWriter) SkipCache

func (cr *CacheResponseWriter) SkipCache() *CacheResponseWriter

func (*CacheResponseWriter) Write

func (cr *CacheResponseWriter) Write(b []byte) (int, error)

func (*CacheResponseWriter) WriteHeader

func (cr *CacheResponseWriter) WriteHeader(status int)

type CachedHTTPHandler

type CachedHTTPHandler struct {
	*zerolog.Logger
	// contains filtered or unexported fields
}

func NewCachedHTTPHandler

func NewCachedHTTPHandler(cache Cache, f func(http.ResponseWriter, *http.Request)) CachedHTTPHandler

func (CachedHTTPHandler) ServeHTTP

func (ch CachedHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type DummyCache

type DummyCache struct{}

func (DummyCache) Get

func (DummyCache) Get(string) ([]byte, error)

func (DummyCache) Set

type HTTP2Server

type HTTP2Server struct {
	sync.RWMutex
	*logging.Logging
	*util.ContextDaemon
	// contains filtered or unexported fields
}

func NewHTTP2Server

func NewHTTP2Server(
	bind, host string, certs []tls.Certificate, encs *encoder.Encoders, networkID base.NetworkID,
) (*HTTP2Server, error)

func (*HTTP2Server) HandleRequest

func (sv *HTTP2Server) HandleRequest(wrapper RequestWrapper)

func (*HTTP2Server) Initialize

func (sv *HTTP2Server) Initialize() error

func (*HTTP2Server) Queue

func (sv *HTTP2Server) Queue() chan RequestWrapper

func (*HTTP2Server) Router

func (sv *HTTP2Server) Router() *mux.Router

func (*HTTP2Server) SetEncoder

func (sv *HTTP2Server) SetEncoder(encs *encoder.Encoders)

func (*HTTP2Server) SetNetworkClientFunc

func (sv *HTTP2Server) SetNetworkClientFunc(f func() (*isaacnetwork.BaseClient, *quicmemberlist.Memberlist, []quicstream.ConnInfo, error)) *HTTP2Server

func (*HTTP2Server) SetRouter

func (sv *HTTP2Server) SetRouter(router *mux.Router)

type Hal

type Hal interface {
	RawInterface() []byte
	Interface() interface{}
	SetInterface(interface{}) Hal
	Self() HalLink
	SetSelf(HalLink) Hal
	Links() map[string]HalLink
	AddLink(rel string, link HalLink) Hal
	Extras() map[string]interface{}
	AddExtras(string, interface{}) Hal
}
type HalLink struct {
	// contains filtered or unexported fields
}
func NewHalLink(href string, properties map[string]interface{}) HalLink

func (HalLink) Href

func (hl HalLink) Href() string

func (HalLink) MarshalJSON

func (hl HalLink) MarshalJSON() ([]byte, error)

func (HalLink) Properties

func (hl HalLink) Properties() map[string]interface{}

func (HalLink) SetProperty

func (hl HalLink) SetProperty(key string, value interface{}) HalLink

func (HalLink) SetTemplated

func (hl HalLink) SetTemplated() HalLink

func (HalLink) URL

func (hl HalLink) URL() (*url.URL, error)

func (*HalLink) UnmarshalJSON

func (hl *HalLink) UnmarshalJSON(b []byte) error

type HalLinkJSONUnpacker

type HalLinkJSONUnpacker struct {
	Href       string                 `json:"href"`
	Properties map[string]interface{} `json:"properties,omitempty"`
}

type HandlerFunc

type HandlerFunc func(*Handlers, http.ResponseWriter, *http.Request)

type Handlers

type Handlers struct {
	*zerolog.Logger

	ItemsLimiter func(string) int64
	// contains filtered or unexported fields
}

func NewHandlers

func NewHandlers(
	ctx context.Context,
	networkID base.NetworkID,
	encs *encoder.Encoders,
	enc encoder.Encoder,
	st *digest.Database,
	cache Cache,
	router *mux.Router,
	queue chan RequestWrapper,
	node quicstream.ConnInfo,
) *Handlers

func (*Handlers) Cache

func (hd *Handlers) Cache() Cache

func (*Handlers) CombineURL

func (hd *Handlers) CombineURL(path string, pairs ...string) (string, error)

func (*Handlers) Database

func (hd *Handlers) Database() *digest.Database

func (*Handlers) Encoder

func (hd *Handlers) Encoder() encoder.Encoder

func (*Handlers) Encoders

func (hd *Handlers) Encoders() *encoder.Encoders

func (*Handlers) ExpireLongLived

func (hd *Handlers) ExpireLongLived() time.Duration

func (*Handlers) ExpireNotFilled

func (hd *Handlers) ExpireNotFilled() time.Duration

func (*Handlers) ExpireShortLived

func (hd *Handlers) ExpireShortLived() time.Duration

func (*Handlers) Handler

func (hd *Handlers) Handler() http.Handler

func (*Handlers) Initialize

func (hd *Handlers) Initialize() error

func (*Handlers) RG

func (hd *Handlers) RG() *singleflight.Group

func (*Handlers) Router

func (hd *Handlers) Router() *mux.Router

func (*Handlers) Routes

func (hd *Handlers) Routes() map[string]*mux.Route

func (*Handlers) SetEncoder

func (hd *Handlers) SetEncoder(encoder encoder.Encoder)

func (*Handlers) SetEncoders

func (hd *Handlers) SetEncoders(encoders *encoder.Encoders)

func (*Handlers) SetHandler

func (hd *Handlers) SetHandler(prefix string, h HandlerFunc, useCache bool, rps, burst int) *mux.Route

func (*Handlers) SetLimiter

func (hd *Handlers) SetLimiter(f func(string) int64) *Handlers

func (*Handlers) SetNetworkClientFunc

func (hd *Handlers) SetNetworkClientFunc(f func() (*quicstream.ConnectionPool, *quicmemberlist.Memberlist, []quicstream.ConnInfo, error)) *Handlers

type LocalMemCache

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

func NewLocalMemCache

func NewLocalMemCache(size int, expire time.Duration) *LocalMemCache

func (*LocalMemCache) Get

func (ca *LocalMemCache) Get(key string) ([]byte, error)

func (*LocalMemCache) Set

func (ca *LocalMemCache) Set(key string, b []byte, expire time.Duration) error

type Memcached

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

func NewMemcached

func NewMemcached(servers ...string) (*Memcached, error)

func (*Memcached) Get

func (mc *Memcached) Get(key string) ([]byte, error)

func (*Memcached) Set

func (mc *Memcached) Set(key string, b []byte, expire time.Duration) error

type Problem

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

Problem implements "Problem Details for HTTP APIs"<https://tools.ietf.org/html/rfc7807>.

func NewProblem

func NewProblem(t, title string) Problem

func NewProblemFromError

func NewProblemFromError(err error) Problem

func (Problem) Error

func (pr Problem) Error() string

func (Problem) Hint

func (Problem) Hint() hint.Hint

func (Problem) SetDetail

func (pr Problem) SetDetail(detail string) Problem

func (Problem) SetExtra

func (pr Problem) SetExtra(key string, value interface{}) Problem

func (Problem) SetTitle

func (pr Problem) SetTitle(title string) Problem

type RequestWrapper

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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