utils

package
v0.0.0-...-2c539bb Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP get client ip

func ExtractPagingParams

func ExtractPagingParams(req *restful.Request, minPageSize, maxPageSize int) (int, int, error)

ExtractPagingParams extract `page` and `pageSize` params from request

func FirstLower

func FirstLower(s string) string

FirstLower Sets the first letter of the string to lowercase.

func FirstUpper

func FirstUpper(s string) string

FirstUpper Sets the first letter of the string to upper.

func GenerateVersion

func GenerateVersion(pre string) string

GenerateVersion Generate version numbers by time

func GetDefaultUIType

func GetDefaultUIType(apiType string, haveOptions bool, subType string, haveSub bool) string

GetDefaultUIType Set the default mapping for API Schema Type

func RenderLabel

func RenderLabel(source interface{}) string

RenderLabel render option label

func StringsContain

func StringsContain(items []string, source string) bool

StringsContain strings contain

Types

type GroupOption

type GroupOption struct {
	Label string   `json:"label"`
	Keys  []string `json:"keys"`
}

GroupOption define multiple data structure composition options.

type MemoryCache

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

MemoryCache memory cache, support time expired

func NewMemoryCache

func NewMemoryCache(data interface{}, cacheDuration time.Duration) *MemoryCache

NewMemoryCache new memory cache instance

func (*MemoryCache) GetData

func (m *MemoryCache) GetData() interface{}

GetData get cache data

func (*MemoryCache) IsExpired

func (m *MemoryCache) IsExpired() bool

IsExpired whether the cache data expires

type Option

type Option struct {
	Label string      `json:"label"`
	Value interface{} `json:"value"`
}

Option select option

type ResponseCapture

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

ResponseCapture capture response and get response info

func NewResponseCapture

func NewResponseCapture(w http.ResponseWriter) *ResponseCapture

NewResponseCapture new response capture

func (ResponseCapture) Bytes

func (c ResponseCapture) Bytes() []byte

Bytes return response body bytes

func (ResponseCapture) Header

func (c ResponseCapture) Header() http.Header

Header return response writer header

func (ResponseCapture) StatusCode

func (c ResponseCapture) StatusCode() int

StatusCode return status code

func (ResponseCapture) Write

func (c ResponseCapture) Write(data []byte) (int, error)

Write write data to response writer and body

func (*ResponseCapture) WriteHeader

func (c *ResponseCapture) WriteHeader(statusCode int)

WriteHeader write header to response writer

type Style

type Style struct {
	// ColSpan the width of a responsive layout
	ColSpan int `json:"colSpan"`
}

Style ui style

type UIParameter

type UIParameter struct {
	Sort        uint      `json:"sort"`
	Label       string    `json:"label"`
	Description string    `json:"description"`
	Validate    *Validate `json:"validate,omitempty"`
	JSONKey     string    `json:"jsonKey"`
	UIType      string    `json:"uiType"`
	Style       *Style    `json:"style,omitempty"`
	// means disable parameter in ui
	Disable                 *bool          `json:"disable,omitempty"`
	SubParameterGroupOption []GroupOption  `json:"subParameterGroupOption,omitempty"`
	SubParameters           []*UIParameter `json:"subParameters,omitempty"`
	AdditionalParameter     *UIParameter   `json:"additionalParameter,omitempty"`
	Additional              *bool          `json:"additional,omitempty"`
}

UIParameter Structured import table simple UI model

type UISchema

type UISchema []*UIParameter

UISchema ui schema

type Validate

type Validate struct {
	Required     bool        `json:"required,omitempty"`
	Max          *float64    `json:"max,omitempty"`
	MaxLength    *uint64     `json:"maxLength,omitempty"`
	Min          *float64    `json:"min,omitempty"`
	MinLength    uint64      `json:"minLength,omitempty"`
	Pattern      string      `json:"pattern,omitempty"`
	Options      []Option    `json:"options,omitempty"`
	DefaultValue interface{} `json:"defaultValue,omitempty"`
	// the parameter cannot be changed twice.
	Immutable bool `json:"immutable"`
}

Validate parameter validate rule

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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