Documentation ¶
Index ¶
- type Event
- func (e Event) Body() EventBody
- func (e Event) Flush()
- func (e Event) Headers() EventHeaders
- func (e Event) Host() (string, error)
- func (e Event) Method() (string, error)
- func (e Event) Path() (string, error)
- func (e Event) Query() Queries
- func (e Event) Redirect(url string) httpRedirect
- func (e Event) Return(code int) error
- func (e Event) UserAgent() (string, error)
- func (e Event) Write(data []byte) (int, error)
- type EventBody
- type EventHeaders
- type Queries
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event uint32
func (Event) Body ¶
Example ¶
package main import ( "fmt" "io/ioutil" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Body: []byte("Hello, world!"), }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } body := httpEvent.Body() data, err := ioutil.ReadAll(body) if err != nil { return } err = body.Close() if err != nil { return } fmt.Println(string(data)) }
Output: Hello, world!
func (Event) Headers ¶
func (e Event) Headers() EventHeaders
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Headers: map[string]string{ "Content-Type": "application/json", }, }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } headers := httpEvent.Headers() contentType, err := headers.Get("Content-Type") if err != nil { return } fmt.Println("Received content type:", contentType) headersList, err := headers.List() if err != nil { return } fmt.Println("Headers:", headersList) err = headers.Set("Content-Type", "text/csv") if err != nil { return } contentType, err = headers.Get("Content-Type") if err != nil { return } fmt.Println("New content type:", contentType) }
Output: Received content type: application/json Headers: [Content-Type] New content type: text/csv
func (Event) Host ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Host: "hal.computers.com", }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } host, err := httpEvent.Host() if err != nil { return } fmt.Println("Host:", host) }
Output: Host: hal.computers.com
func (Event) Method ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Method: "POST", }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } method, err := httpEvent.Method() if err != nil { return } fmt.Println("Method:", method) }
Output: Method: POST
func (Event) Path ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Path: "/test/v1", }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } path, err := httpEvent.Path() if err != nil { return } fmt.Println("Path:", path) }
Output: Path: /test/v1
func (Event) Query ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, Queries: map[string]string{ "username": "taubyte", }, }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } query := httpEvent.Query() username, err := query.Get("username") if err != nil { return } if username != "taubyte" { return } queryList, err := query.List() if err != nil { return } fmt.Println("Queries:", queryList) }
Output: Queries: [username]
func (Event) Redirect ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := httpEventSym.MockData{ EventType: common.EventTypeHttp, }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } err = httpEvent.Redirect("https://google.com").Temporary() if err != nil { return } fmt.Println(m.RedirectedTo) }
Output: https://google.com
func (Event) Return ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := httpEventSym.MockData{ EventType: common.EventTypeHttp, }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } err = httpEvent.Return(404) if err != nil { return } fmt.Println("Code:", m.ReturnCode) }
Output: Code: 404
func (Event) UserAgent ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground httpEventSym.MockData{ EventType: common.EventTypeHttp, UserAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/517.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/5447.36", }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } path, err := httpEvent.UserAgent() if err != nil { return } fmt.Println("UserAgent:", path) }
Output: UserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/517.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/5447.36
func (Event) Write ¶
Example ¶
package main import ( "fmt" httpEventSym "github.com/taubyte/go-sdk-symbols/http/event" "github.com/taubyte/go-sdk/common" "github.com/taubyte/go-sdk/event" ) func main() { // Mocking the calls to the vm for usage in tests and playground m := httpEventSym.MockData{ EventType: common.EventTypeHttp, }.Mock() var e event.Event httpEvent, err := e.HTTP() if err != nil { return } toWrite := []byte("Hello, world!") n, err := httpEvent.Write(toWrite) if err != nil { return } if len(toWrite) != n { return } fmt.Println("ReturnBody:", string(m.ReturnBody)) }
Output: ReturnBody: Hello, world!
type EventHeaders ¶
type EventHeaders uint32
func (EventHeaders) List ¶
func (e EventHeaders) List() ([]string, error)
func (EventHeaders) Set ¶
func (e EventHeaders) Set(key, value string) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.