Documentation ¶
Overview ¶
Package goatfile provides functionalities to unmarshal and parse a Goatfile.
Here you can find the Goatfile specification on which basis this parser in built on. https://github.com/studio-b12/goat/blob/main/docs/goatfile-spec.md
Index ¶
- Constants
- Variables
- func ApplyTemplate(raw string, params any) (string, error)
- func ApplyTemplateBuf(raw string, params any) (*bytes.Buffer, error)
- func ApplyTemplateToArray(arr []any, params any) (err error)
- func ApplyTemplateToMap(m map[string]any, params any) (err error)
- func Extend(v string, ext string) string
- func IsNoContent(d Data) bool
- type Action
- type ActionType
- type Data
- type Execute
- type FileContent
- type Goatfile
- type LogSection
- type NoContent
- type Opts
- type ParameterValue
- type ParseError
- type Parser
- type Request
- type SectionName
- type StringContent
Constants ¶
const ( ActionRequest = ActionType(iota + 1) ActionLogSection ActionExecute )
const ( SectionSetup = SectionName("setup") SectionTests = SectionName("tests") SectionTeardown = SectionName("teardown") SectionDefaults = SectionName("defaults") )
const FileExtension = "goat"
Variables ¶
var ( ErrTemplateAlreadyParsed = errors.New("request template has already been parsed") ErrTemplateAlreadyPreParsed = errors.New("request template has already been pre-parsed") ErrIllegalCharacter = errors.New("illegal character") ErrUnexpected = errors.New("unexpected error") ErrInvalidStringLiteral = errors.New("invalid string literal") ErrEmptyUsePath = errors.New("empty use path") ErrEmptyCallPath = errors.New("empty call path") ErrInvalidSection = errors.New("invalid section") ErrInvalidLogSection = errors.New("invalid log section") ErrInvalidRequestMethod = errors.New("invalid request method") ErrNoRequestURI = errors.New("method must be followed by the request URI") ErrInvalidToken = errors.New("invalid token") ErrInvalidLiteral = errors.New("invalid literal") ErrInvalidBlockHeader = errors.New("invalid block header") ErrInvalidBlockEntryAssignment = errors.New("block entry must start with an assignment") ErrInvalidHeaderKey = errors.New("header values must start with a key") ErrInvalidHeaderSeparator = errors.New("header key and value must be separated by a colon (:)") ErrNoHeaderValue = errors.New("no header value") ErrFollowingImport = errors.New("failed following import") ErrOpenEscapeBlock = errors.New("open escape block") ErrBlockOutOfRequest = errors.New("blocks must follow after a request head") ErrMultiImport = errors.New("the impoted resource has already been imported") ErrInvalidFileDescriptor = errors.New("invalid file descriptor") ErrSectionDefinedMultiple = errors.New("the section has been already defined") ErrUnclosedGroup = errors.New("group has not been closed") ErrMissingGroup = errors.New("missing group definition") )
Functions ¶
func ApplyTemplate ¶ added in v0.13.0
ApplyTemplate parses the given raw string as a template and applies the given values in params onto it returning the result as string.
If a key in the template is not present in the params, an error will be returned.
func ApplyTemplateBuf ¶ added in v0.13.0
ApplyTemplateBuf parses the given raw string as a template and applies the given values in params onto it returning the result as bytes buffer.
If a key in the template is not present in the params, an error will be returned.
func ApplyTemplateToArray ¶ added in v0.13.0
ApplyTemplateToArray executes applyTemplate on all string instances in the given array or sub arrays.
func ApplyTemplateToMap ¶ added in v0.13.0
ApplyTemplateToMap executes applyTemplate on all values in the given map.
func Extend ¶ added in v0.13.0
Extend takes a file path and adds the given extension to it if the path does not end with any file extension.
func IsNoContent ¶ added in v0.11.0
Types ¶
type Action ¶ added in v0.9.0
type Action interface {
Type() ActionType
}
Action is used to determine the ActionType of an action definition used to cast the action to the specific Action implementation.
type ActionType ¶ added in v0.9.0
type ActionType int
type Data ¶ added in v0.4.0
type Data interface { // Reader returns a reader to ther internal // data or an error. The returned reader // might be nil. Reader() (io.Reader, error) }
Data provides a getter to receive a reader to internal data.
func DataFromAst ¶ added in v1.1.0
func DataFromAst(di ast.DataContent, path string) (Data, error)
type Execute ¶ added in v0.13.0
func ExecuteFromAst ¶ added in v1.1.0
func (Execute) Type ¶ added in v0.13.0
func (t Execute) Type() ActionType
type FileContent ¶ added in v0.7.0
type FileContent struct {
// contains filtered or unexported fields
}
FileContent provides a getter which opens a file with the stored path and returns it as reader.
type Goatfile ¶
type Goatfile struct { Imports []string Defaults *Request Setup []Action Tests []Action Teardown []Action Path string }
Goatfile holds all sections and their requests.
func Unmarshal ¶
Unmarshal takes a raw string of a Goatfile and tries to parse it. Returns the parsed Goatfile.
type LogSection ¶ added in v0.9.0
type LogSection string
func (LogSection) Type ¶ added in v0.9.0
func (t LogSection) Type() ActionType
type NoContent ¶ added in v0.7.0
type NoContent struct{}
NoContent implements Data containing no content.
type ParameterValue ¶
type ParameterValue string
ParameterValue holds a go template value as string allowing to apply parameters onto it and parsing the result.
func (ParameterValue) ApplyTemplate ¶
func (t ParameterValue) ApplyTemplate(params any) (any, error)
ApplyTemplate applies the passed params onto the teplate value and parses the result using a new instance of Parser as sub-parser.
type ParseError ¶
type ParseError struct { errs.InnerError Line int LinePos int }
ParseError wraps an inner error with additional parsing context.
func (ParseError) Error ¶
func (t ParseError) Error() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses a Goatfile.
type Request ¶
type Request struct { Opts Method string URI string Header http.Header Body Data PreScript Data Script Data Path string PosLine int // contains filtered or unexported fields }
Request holds the specifications for a HTTP request with options and script commands.
func PartialRequestFromAst ¶ added in v1.1.0
func PartialRequestFromAst(req ast.PartialRequest, path string) (t Request, err error)
func RequestFromAst ¶ added in v1.1.0
func (*Request) PreSubstitudeWithParams ¶ added in v0.15.0
PreSubstitudeWithParams takes the given parameters and replaces placeholders within specific parts of the request which shall be executed before the actual request is substituted (like PreScript).
func (*Request) SubstitudeWithParams ¶ added in v0.15.0
SubstitudeWithParams takes the given parameters and replaces placeholders within the request with values from the given params.
func (Request) ToHttpRequest ¶
ToHttpRequest returns a *http.Request built from the given Reuqest.
func (Request) Type ¶ added in v0.9.0
func (t Request) Type() ActionType
type SectionName ¶ added in v0.13.1
type SectionName string
type StringContent ¶ added in v0.7.0
type StringContent string
StringContent stores data as a string.