dvcontext

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UrlPathPrefix = "URL_PATH_"
	ErrorPolicy   = "ERROR_POLICY"
)
View Source
const (
	HeadersAddToList       = iota
	HeadersSetOrigin       = iota
	HeadersSetOriginAlways = iota
)
View Source
const (
	LogLevelNone      = iota
	LogLevelInputURL  = iota
	LogLevelFullInput = iota
	LogLevelFull      = iota
)
View Source
const (
	PARALLEL_MODE_SIMPLE = 0
	PARALLEL_MODE_SSE    = 1
	PARALLEL_MODE_WS     = 2
)
View Source
const (
	STAGE_MODE_START  = 0
	STAGE_MODE_MIDDLE = 1
	STAGE_MODE_END    = 2
)
View Source
const (
	UrlIncludeOption_HostFirst          = 1
	UrlIncludeOption_PredefinedHostOnly = 2
	UrlIncludeOption_HostWithoutPort    = 4
)
View Source
const (
	BODY_STRING           = "BODY_STRING"
	BODY_JSON             = "BODY_JSON"
	BODY_STRING_ARRAY_MAP = "BODY_STRING_ARRAY_MAP"
	BODY_STRING_MAP       = "BODY_STRING_MAP"
	BODY_PARAM_PREFIX     = "BODY_PARAM_"
	REQUEST_METHOD        = "REQUEST_METHOD"
	REQUEST_URI           = "REQUEST_URI"
	REQUEST_URL_PARAMS    = "REQUEST_URL_PARAMS"
	AUTO_HEADER_SET_BY    = "AUTO_HEADER_SET_BY"
	HEADERS_RESPONSE      = "HEADERS_RESPONSE"
)
View Source
const (
	DoNotShowPlaceInfo = "~DO NOT SHOW PLACE~"
)
View Source
const ENCODED_HOST_PORT_URL_PARAM = "_ENCODED_HOST_PORT_URL_PARAM_"
View Source
const LogHandled = -2000
View Source
const (
	ServerSessionStoringKey = "___SERVER__SESSION__STORING__KEY___"
)

*** SessionActionRequest options: c - create session u - update session only e - error if no session l - load all session variables with SESSION_ prefix (default) or without n - specifies option "l" must be without prefix

id is a place where to find the session id

Variables

View Source
var DefaultRequestErrorPolicy = &RequestErrorPolicy{
	Name:         "default",
	Format:       "{\"timestamp\":\"$$$TIMESTAMP\",\"status\":$$$STATUS,\"error\":\"$$$ERROR\",\"message\":\"$$$MESSAGE\",\"path\":\"$$$PATH\"}",
	ContentType:  "application/json",
	FormatForced: false,
}

Functions

func GetPurePath

func GetPurePath(path string) string

func GetUniqueId

func GetUniqueId() int64

func HandleError

func HandleError(request *RequestContext, message string)

func HandlerError

func HandlerError(w http.ResponseWriter, r *http.Request, message string)

func HandlerOk

func HandlerOk(w http.ResponseWriter, r *http.Request, message string)

func MatchByContainMap

func MatchByContainMap(src []byte, containMap map[byte]int) bool

func PrepareValidatePattern

func PrepareValidatePattern(pattern *ValidatePattern, defContainMap map[byte]int, defRegPattern *regexp.Regexp) error

func ProvideHeaders

func ProvideHeaders(preHeaders map[string][]string, postHeaders map[string][]string, origin string, specialHeaders map[string]MicroCoreHeaderAttribute, w http.ResponseWriter)

func Send

func Send(w http.ResponseWriter, r *http.Request, message []byte)

func SetRecordMode

func SetRecordMode(path string)

Types

type ActionPolicy

type ActionPolicy struct {
	LogFirstTimes int `json:"log_first_times"`
	LogNextTime   int `json:"log_next_time"`
}

type DatabaseConfig

type DatabaseConfig struct {
	Name    string           `json:"name"`
	Root    string           `json:"root"`
	WebRoot string           `json:"webroot"`
	Tables  []*DatabaseTable `json:"tables"`
}

type DatabaseTable

type DatabaseTable struct {
	Name          string `json:"name"`
	Kind          string `json:"kind"`
	Web           string `json:"web"`
	KeyFirst      string `json:"keyFirst"`
	WebField      string `json:"webField"`
	WebFileName   string `json:"webFileName"`
	WebFormats    string `json:"webFormats"`
	AllowCustomId bool   `json:"customId"`
	Version       string `json:"version"`
}

type DvAction

type DvAction struct {
	Name        string                `json:"name"`
	Typ         string                `json:"type"`
	Url         string                `json:"url"`
	Method      string                `json:"method"`
	QueryParams map[string]string     `json:"query"`
	Body        map[string]string     `json:"body"`
	Result      string                `json:"result"`
	ResultMode  string                `json:"mode"`
	Definitions map[string]string     `json:"definitions"`
	InnerParams string                `json:"params"`
	Conditions  map[string]string     `json:"conditions"`
	Validations []*ValidatePattern    `json:"validations"`
	ErrorPolicy string                `json:"error_policy"`
	LogPolicy   string                `json:"log_policy"`
	Session     *SessionActionRequest `json:"session"`
	Roles       string                `json:"roles"`
	Auth        string                `json:"auth"`
	SseWs       *SSEWSControl         `json:"sse_ws"`
}

func (*DvAction) CloneFrom

func (action *DvAction) CloneFrom(other *DvAction)

type HandlerFunc

type HandlerFunc func(request *RequestContext) bool

type InterfaceExecutor

type InterfaceExecutor func(*RequestContext, interface{}) interface{}

type MaskInfo

type MaskInfo struct {
	FixedStart        string
	FixedEnd          string
	Middle            []*MaskInfoPart
	IsNegative        bool
	IsCaseInsensitive int
}

type MaskInfoPart

type MaskInfoPart struct {
	Min       int
	Max       int
	Kind      MaskKind
	Regex     *regexp.Regexp
	Data      string
	Condition string
}

type MaskKind

type MaskKind int
const (
	MaskWord MaskKind = iota
	MaskSlashAware
	MaskSlashUnaware
	MaskRegExp
	MaskCondition
)

type MicroCoreHeaderAttribute

type MicroCoreHeaderAttribute struct {
	Kind  int
	Imap  map[string]int
	List  []string
	Plain string
}

type MicroCoreInfo

type MicroCoreInfo struct {
	sync.RWMutex
	Client                    *http.Client
	BaseFolderUsed            bool
	ExtraStaticServer         bool
	ProxyServerHttp           bool
	HasProxyServers           bool
	BaseFolderUrl             string
	ProxyServerMap            map[string]string
	ProxyServerUrl            string
	ProxyServerSettings       ServerSettings
	ProxyName                 string
	DomainName                string
	ProxyServers              []*ProxyServerBlock
	ErrorPolicies             map[string]*RequestErrorPolicy
	HeadersStatic             map[string][]string
	HeadersProxyServer        map[string][]string
	HeadersStaticOptions      map[string][]string
	HeadersProxyServerOptions map[string][]string
	HeadersSpecial            map[string]MicroCoreHeaderAttribute
	HeadersSpecialOptions     map[string]MicroCoreHeaderAttribute
	HeadersSpecialStatic      map[string]MicroCoreHeaderAttribute
	DirectoryIndex            []string
	BaseRewrite               RewriteMap
	BaseProcessorBlocks       []ProcessorBlock
	BaseProviderBlocks        []ProcessorBlock
	PostProcessorBlocks       []ProcessorBlock
	HostHeader                string
	ServerRewrite             RewriteMap
	Session                   ServerSessionProvider
	SecurityInfo              *SecurityServerInfo
	ModuleHandler             HandlerFunc
	ActionPolicies            map[string]*ActionPolicy
	ActionHandler             HandlerFunc
	LogLevel                  int
	UrlIncludeOption          int
}

type ParallelExecutionControl

type ParallelExecutionControl struct {
	Flusher http.Flusher
	Value   interface{}
}

type ParallelProcessing

type ParallelProcessing struct {
	IntervalTimeUnit float32 `json:"interval_time_unit"`
}

type ProcessorBlock

type ProcessorBlock struct {
	Name            string
	EndPointHandler ProcessorEndPointHandler
	Urls            []*MaskInfo
	Data            map[string]string
}

type ProcessorEndPointHandler

type ProcessorEndPointHandler func(request *RequestContext) bool

type ProxyServerBlock

type ProxyServerBlock struct {
	ServerUrl     string
	FilterUrls    []*MaskInfo
	RewritePoint  int
	RewritePrefix string
}

type RequestContext

type RequestContext struct {
	Id                        int64
	Extra                     map[string]interface{}
	PrimaryContextEnvironment *dvevaluation.DvObject
	LocalContextEnvironment   *dvevaluation.DvObject
	Params                    map[string]string
	UrlInlineParams           map[string]string
	Url                       string
	Urls                      []string
	UrlsLowerCase             []string
	FileName                  string
	DataType                  string
	Queries                   map[string]string
	Writer                    http.ResponseWriter
	Reader                    *http.Request
	Server                    *MicroCoreInfo
	Session                   RequestSession
	Input                     []byte
	InputStr                  string
	InputJson                 interface{}
	Output                    []byte
	Headers                   map[string][]string
	Error                     error
	Action                    *DvAction
	StatusCode                int
	ParallelExecution         *ParallelExecutionControl
	ExecutorFn                InterfaceExecutor
	LogLevel                  int
	PlaceInfo                 string
	TempFiles                 []string
}

func (*RequestContext) AddTempFile

func (ctx *RequestContext) AddTempFile(name string)

func (*RequestContext) CleanUpRequest

func (ctx *RequestContext) CleanUpRequest()

func (*RequestContext) GetContentType

func (request *RequestContext) GetContentType() string

func (*RequestContext) GetCurrentErrorPolicy

func (ctx *RequestContext) GetCurrentErrorPolicy() *RequestErrorPolicy

func (*RequestContext) GetEnvironment

func (ctx *RequestContext) GetEnvironment() *dvevaluation.DvObject

func (*RequestContext) GetUrlInlineParameter

func (ctx *RequestContext) GetUrlInlineParameter(param string) string

func (*RequestContext) GetUrlParameter

func (ctx *RequestContext) GetUrlParameter(param string) string

func (*RequestContext) HandleCommunication

func (request *RequestContext) HandleCommunication()

func (*RequestContext) HandleFileNotFound

func (ctx *RequestContext) HandleFileNotFound()

func (*RequestContext) HandleHttpError

func (ctx *RequestContext) HandleHttpError(statusCode int)

func (*RequestContext) HandleInternalServerError

func (ctx *RequestContext) HandleInternalServerError()

func (*RequestContext) SetError

func (ctx *RequestContext) SetError(err error)

func (*RequestContext) SetErrorMessage

func (ctx *RequestContext) SetErrorMessage(message string)

func (*RequestContext) SetHeaderArray

func (ctx *RequestContext) SetHeaderArray(key string, val []string)

func (*RequestContext) SetHeaderUnique

func (ctx *RequestContext) SetHeaderUnique(key string, val string)

func (*RequestContext) SetHttpErrorCode

func (ctx *RequestContext) SetHttpErrorCode(errorCode int, message string)

func (*RequestContext) SetUrlInlineParameters

func (ctx *RequestContext) SetUrlInlineParameters(params map[string]string)

func (*RequestContext) StoreStoringSession

func (ctx *RequestContext) StoreStoringSession()

type RequestErrorPolicy

type RequestErrorPolicy struct {
	Name         string `json:"name"`
	Format       string `json:"format"`
	ContentType  string `json:"content_type"`
	FormatForced bool   `json:"format_forced"`
}

type RequestSession

type RequestSession interface {
	SetItem(key string, value interface{})
	GetItem(key string) interface{}
	RemoveItem(key string)
	Clear()
	Keys() []string
	Values() map[string]interface{}
	GetId() string
}

type RewriteMap

type RewriteMap map[string][]*RewriteMapItem

type RewriteMapItem

type RewriteMapItem struct {
	Url    string
	UrlLen int
	Full   bool
	Src    string
}

type SSEChange

type SSEChange struct {
	ActionCheck      string   `json:"action_check"`
	ActionCheckVar   string   `json:"action_check_var"`
	ActionFull       string   `json:"action_full"`
	ActionFullResult string   `json:"action_full_result"`
	Places           []string `json:"places"`
}

type SSEWSControl

type SSEWSControl struct {
	Change          *SSEChange `json:"change"`
	Start           *Stage     `json:"start"`
	Mid             *Stage     `json:"mid"`
	End             *Stage     `json:"end"`
	Interval        int        `json:"interval"`
	TimeOut         int        `json:"time_out"`
	HeartBeat       int        `json:"heart_beat"`
	ServeMidAtStart bool       `json:"serve_mid_at_start"`
}

type SecurityServerInfo

type SecurityServerInfo struct {
	RolePrefix      string   `json:"role_prefix"`
	SuperAdminRoles []string `json:"super_admin_roles"`
}

type ServerSessionProvider

type ServerSessionProvider interface {
	GetSessionStorage(ctx *RequestContext, request *SessionActionRequest, sessionId string) (RequestSession, error)
}

type ServerSettings

type ServerSettings struct {
	MaxIdleConns          int  `json:"maxIdleConnections"`
	IdleConnTimeout       int  `json:"idleConnectionTimeout"`
	DisableCompression    bool `json:"disableCompression"`
	DisableKeepAlives     bool `json:"disableKeepAlives"`
	MaxIdleConnsPerHost   int  `json:"maxIdleConnectionsPerHost"`
	ResponseHeaderTimeout int  `json:"responseHeaderTimeout"`
	ExpectContinueTimeout int  `json:"expectContinueTimeout"`
}

type SessionActionRequest

type SessionActionRequest struct {
	Prefix string   `json:"prefix"`
	Option string   `json:"option"`
	Id     []string `json:"id"`
}

type Stage

type Stage struct {
	Action    string `json:"action"`
	Condition string `json:"condition"`
	Result    string `json:"result"`
}

type ValidatePattern

type ValidatePattern struct {
	Source       string `json:"source"`
	Message      string `json:"message"`
	EmptyMessage string `json:"empty"`
	Contains     string `json:"contains"`
	RegPattern   string `json:"pattern"`
	// contains filtered or unexported fields
}

func (*ValidatePattern) Match

func (pattern *ValidatePattern) Match(src string) string

func (*ValidatePattern) MatchByCompiledPattern

func (pattern *ValidatePattern) MatchByCompiledPattern(src string) string

Jump to

Keyboard shortcuts

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