Documentation
¶
Index ¶
- Constants
- type DomainConfig
- func (d *DomainConfig) BuildVars(envName, envFile string) (maputil.Data, error)
- func (d *DomainConfig) DefaultTemplates() *Templates
- func (d *DomainConfig) EnvVars(env string) maputil.Data
- func (d *DomainConfig) Init() error
- func (d *DomainConfig) Load() error
- func (d *DomainConfig) LoadConfig() error
- func (d *DomainConfig) Lookup(group, name string) (*Template, error)
- func (d *DomainConfig) LookupVars(env string) (maputil.Data, bool)
- func (d *DomainConfig) Template(name string) *Template
- func (d *DomainConfig) Templates(group string) (*Templates, bool)
- type EnvsMap
- type Manager
- type Response
- type Template
- func (t *Template) BuildRequest(vars maputil.Data, hs map[string]string) (*http.Request, error)
- func (t *Template) BuildRequestBody(vars maputil.Data) (io.Reader, error)
- func (t *Template) ContentType() string
- func (t *Template) FromHCString(s string) error
- func (t *Template) FromJSONBytes(bs []byte) error
- func (t *Template) FromJSONFile(p string) error
- func (t *Template) FromJSONString(s string) error
- func (t *Template) Path() string
- func (t *Template) RequestString(vars maputil.Data) string
- func (t *Template) Send(vars maputil.Data, hs map[string]string, opt *httpreq.Option) error
- func (t *Template) SetTimeout(ms int)
- func (t *Template) String() string
- func (t *Template) Type() string
- type Templates
- func (ts *Templates) All() map[string]*Template
- func (ts *Templates) Each(fn func(t *Template))
- func (ts *Templates) FindOne(keywords string) *Template
- func (ts *Templates) FromHCFile(hcFile string) error
- func (ts *Templates) FromHCString(s string) error
- func (ts *Templates) Get(name string) *Template
- func (ts *Templates) GetByPath(path string) *Template
- func (ts *Templates) IsDefType() bool
- func (ts *Templates) IsHcType() bool
- func (ts *Templates) IsTplType() bool
- func (ts *Templates) LoadAll() error
- func (ts *Templates) LoadTemplate(name string) (*Template, error)
- func (ts *Templates) Lookup(name string) (*Template, error)
- func (ts *Templates) Search(keywords string, limit int) []*Template
- func (ts *Templates) Send(keywords string) error
- func (ts *Templates) String() string
Constants ¶
const ( TypeDefinition = "definition" // request definition spec/template files TypeHttpClient = "http-client" // a IDE http-client file )
Templates type constants const TypeTemplate = "template" // request definition template files
const BodySplit = "\n\n"
const HcFileExt = ".http"
HcFileExt name
const RequestSplit = "\n###"
const StartPrefix = "###"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DomainConfig ¶
type DomainConfig struct {
// Name domain name
Name string `json:"name"`
// ConfigFile domain config file path
ConfigFile string `json:"config_file"`
// PathResolver handler
PathResolver func(path string) string `json:"-"`
// TplDir path for request templates.
//
// default is: {ConfigFile Dir}/{domainName}
TplDir string `json:"tpl_dir"`
// TplExt allowed template file ext list
TplExt []string `json:"tpl_ext"`
// Vars global variables
Vars maputil.Data `json:"vars"`
// Header global headers for send request
Header map[string]string `json:"header"`
// DefaultEnv name
DefaultEnv string `json:"default_env"`
// EnvFile The ide http-client.env.json file path
EnvFile string `json:"env_file"`
// Envs definition
Envs EnvsMap `json:"envs"`
// contains filtered or unexported fields
}
DomainConfig struct. name: domain, topic, collection
func NewDomainConfig ¶
func NewDomainConfig(name, configFile string) *DomainConfig
NewDomainConfig instance
func (*DomainConfig) BuildVars ¶
func (d *DomainConfig) BuildVars(envName, envFile string) (maputil.Data, error)
BuildVars by env name and file
func (*DomainConfig) DefaultTemplates ¶
func (d *DomainConfig) DefaultTemplates() *Templates
DefaultTemplates get by name
func (*DomainConfig) EnvVars ¶
func (d *DomainConfig) EnvVars(env string) maputil.Data
EnvVars get by env name
func (*DomainConfig) LoadConfig ¶
func (d *DomainConfig) LoadConfig() error
LoadConfig file and env file
func (*DomainConfig) Lookup ¶
func (d *DomainConfig) Lookup(group, name string) (*Template, error)
Lookup get by name and group
func (*DomainConfig) LookupVars ¶
func (d *DomainConfig) LookupVars(env string) (maputil.Data, bool)
LookupVars get by env name
func (*DomainConfig) Template ¶
func (d *DomainConfig) Template(name string) *Template
Template get by file name, will find from tsMap[DomainConfig.Name]
type Manager ¶
type Manager struct {
// DefaultExt default config file ext, for auto load domain config
//
// Allow: json, json5, yaml
DefaultExt string `json:"default_ext"`
// DefaultDir default domain config file dir, for auto load domain config
//
// path format: {DefaultDir}/{domainName}-domain.{DefaultExt}
DefaultDir string `json:"default_dir"`
// Domains config definitions
Domains map[string]*DomainConfig `json:"domains"`
// PathResolver handler
PathResolver func(path string) string
}
Manager HTTP tpl manager
type Response ¶
type Response struct {
Status int `json:"status"`
Struct any `json:"struct"`
ContentType string `json:"content_type"`
// Required fields in response.
Required []string `json:"required"`
// Asserts {name: "$.name == inhere"}
Asserts map[string]any `json:"asserts"`
}
Response struct
type Template ¶
type Template struct {
// Index value
Index int
// Version info
Version string `json:"version"`
Kind string `json:"kind"`
Name string `json:"name"`
Desc string `json:"desc"`
// URL string for request remote, full URL.
URL string `json:"url"`
Method string `json:"method"`
// Query for request url
Query map[string]any `json:"query"`
// Header for request
Header map[string]string `json:"header"`
// BasicAuth config
BasicAuth *httpreq.BasicAuthConf `json:"basic_auth"`
// Timeout for request, unit: ms
Timeout int `json:"timeout"`
// Body for request
Body any `json:"body"`
// JSON body data, will auto add content type
JSON any `json:"json"`
// Form body data, will auto add content type
Form map[string]any `json:"form"`
// BodyFile will read file contents as body
BodyFile string `json:"body_file"`
// BeforeSend hook
BeforeSend func(r *http.Request, body *bytes.Buffer) `json:"-"`
// AfterSend hook
AfterSend func(w *httpreq.Resp, err error) `json:"-"`
// Resp http response data check
Resp *httpreq.Resp `json:"response"`
// contains filtered or unexported fields
}
Template definition for http request
TIP:
allow use vars in URL, Query, Header, Body, JSON, Form and BodyFile.
func ParseAsTemplate ¶
func (*Template) BuildRequest ¶
BuildRequest instance
func (*Template) BuildRequestBody ¶
BuildRequestBody for request
func (*Template) FromHCString ¶
FromHCString parse from hc-file request part contents
func (*Template) FromJSONBytes ¶
FromJSONBytes init definition template
func (*Template) FromJSONFile ¶
FromJSONFile init definition template
func (*Template) FromJSONString ¶
FromJSONString init definition template
type Templates ¶
type Templates struct {
// contains filtered or unexported fields
}
Templates request set definitions for a group
func ParseAsTemplates ¶
func ParseClientFile ¶
func TemplateFile ¶
func (*Templates) FromHCFile ¶
func (*Templates) FromHCString ¶
func (*Templates) LoadTemplate ¶
LoadTemplate file and register