server

package
v0.0.0-...-b628146 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package ginzap provides log handling using zap package. Code structure based on ginrus package.

Index

Constants

View Source
const (
	NodeCollectionName = "node"
	TopicAliasName     = "topic"
	TopicTypeName      = "topic"

	SizeDefault    = 10
	SizeMax        = 50
	PagingDepthMax = 1000

	ClauseCountMax   = 30
	KeywordLengthMax = 100

	SortTypeSumup   = "sumup"
	SortTypeCreated = "created"

	OrderTypeDesc = 0
	OrderTypeAsc  = 1

	OperatorTypeOr  = "or"
	OperatorTypeAnd = "and"

	ExcludePrefix          = "-"
	MultipleItemsSeparator = ","

	V2EXUserHomepageFormat = "https://www.v2ex.com/member/%v"

	LimiterWaitTimeMax = 5 * time.Second
)

Variables

View Source
var (
	ErrUserNotFound       = errors.New("V2EX user not found")
	ErrGetUserInfoFailed  = errors.New("get user info failed")
	ErrRequestLimitExceed = errors.New("exceed the request limit of getting user info")

	SortTypeChoices     = stringset.NewSet(SortTypeSumup, SortTypeCreated)
	OrderTypeChoices    = int64set.NewSet(OrderTypeDesc, OrderTypeAsc)
	OperatorTypeChoices = stringset.NewSet(OperatorTypeOr, OperatorTypeAnd)
)

Functions

func Ginzap

func Ginzap(logger *zap.Logger, utc bool) gin.HandlerFunc

Ginzap returns a gin.HandlerFunc (middleware) that logs requests using uber-go/zap.

Requests with errors are logged using zap.Error(). Requests without errors are logged using zap.Info().

It receives:

  1. A time package format string (e.g. time.RFC3339).
  2. A boolean stating whether to use UTC time zone or local.

func InitCollection

func InitCollection()

func RenderScoreSearchBody

func RenderScoreSearchBody(params RenderParams) string

func RenderTimeOrderSearchBody

func RenderTimeOrderSearchBody(params RenderParams) string

func ReqErrorWithErr

func ReqErrorWithErr(c *gin.Context, code int, err error)

func ReqErrorWithMessage

func ReqErrorWithMessage(c *gin.Context, code int, msg string)

func SetupEngine

func SetupEngine() *gin.Engine

func StreamRenderScoreSearchBody

func StreamRenderScoreSearchBody(qw422016 *qt422016.Writer, params RenderParams)

func StreamRenderTimeOrderSearchBody

func StreamRenderTimeOrderSearchBody(qw422016 *qt422016.Writer, params RenderParams)

func WriteRenderScoreSearchBody

func WriteRenderScoreSearchBody(qq422016 qtio422016.Writer, params RenderParams)

func WriteRenderTimeOrderSearchBody

func WriteRenderTimeOrderSearchBody(qq422016 qtio422016.Writer, params RenderParams)

Types

type GinRecoverErrorWriter

type GinRecoverErrorWriter struct{}

func (*GinRecoverErrorWriter) Write

func (*GinRecoverErrorWriter) Write(p []byte) (n int, err error)

type RenderParams

type RenderParams struct {
	SearchParams
	NodeIds         []int64
	ExcludedNodeIds []int64
}

func GenerateRenderParams

func GenerateRenderParams(sp SearchParams) (rp RenderParams, err error)

type SearchHit

type SearchHit struct {
	Score     *float64                   `json:"_score"`    // computed score
	Index     string                     `json:"_index"`    // index name
	Type      string                     `json:"_type"`     // type meta field
	Id        string                     `json:"_id"`       // external or internal
	Sort      []interface{}              `json:"sort"`      // sort information
	Highlight elastic.SearchHitHighlight `json:"highlight"` // highlighter information
	Source    *json.RawMessage           `json:"_source"`   // stored document source
}

type SearchParams

type SearchParams struct {
	Keyword  string `schema:"q"`
	From     int64  `schema:"from"`
	Size     int64  `schema:"size"`
	Sort     string `schema:"sort"`
	Order    int64  `schema:"order"`
	Gte      int64  `schema:"gte"`
	Lte      int64  `schema:"lte"`
	Node     string `schema:"node"` // should be split and replaced by node id(int64)
	Operator string `schema:"operator"`
	Username string `schema:"username"`
}

func NewDefaultParams

func NewDefaultParams() SearchParams

type SearchResult

type SearchResult struct {
	TookInMillis int64        `json:"took"`      // search time in milliseconds
	TotalHits    int64        `json:"total"`     // total number of hits found
	Hits         []*SearchHit `json:"hits"`      // the actual search hits
	TimedOut     bool         `json:"timed_out"` // true if the search timed out
}

----- Elasticsearch -----

Jump to

Keyboard shortcuts

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