host

package
v0.0.0-...-d0ebcda Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: BSD-3-Clause Imports: 10 Imported by: 21

Documentation

Index

Examples

Constants

View Source
const (
	HostRoute = "host"
	EtcRoute  = "etc"
)
View Source
const (
	Authorization = "Authorization"
)
View Source
const (
	PkgPath = "github/advanced-go/core/host"
)

Variables

View Source
var Exchange = messaging.NewExchange()

Exchange - host package controller2

Functions

func HttpHandler

func HttpHandler(w http.ResponseWriter, r *http.Request)

HttpHandler - process an HTTP request

Example
pattern := "github/advanced-go/host"
r, _ := http.NewRequest("PUT", "http://localhost:8080/github/advanced-go/host:entry", nil)

RegisterExchange(pattern, appHttpExchange)

rec := httptest.NewRecorder()
HttpHandler(rec, r)

fmt.Printf("test: HttpHandler() -> %v\n", rec.Result().StatusCode)
Output:

test: HttpHandler() -> 418

func NewAccessLogIntermediary

func NewAccessLogIntermediary(traffic string, c2 core.HttpExchange) core.HttpExchange

func NewConditionalIntermediary

func NewConditionalIntermediary(c1 core.HttpExchange, c2 core.HttpExchange, ok func(int) bool) core.HttpExchange

func NewProxyIntermediary

func NewProxyIntermediary(host string, c2 core.HttpExchange) core.HttpExchange

func Ping

func Ping(uri any) *core.Status
Example
uri := "test"
status := Ping(uri)
fmt.Printf("test: Ping(%v) -> [status:%v]\n", uri, status)
Output:

test: Ping(test) -> [status:Internal Error [error: controller2.Send() failed as the message To is empty or invalid : [test]]]

func RegisterControlAgent

func RegisterControlAgent(uri string, handler messaging.Handler) (messaging.Agent, error)

func RegisterExchange

func RegisterExchange(domain string, handler core.HttpExchange) error

RegisterExchange - add a domain and Http Exchange handler to the proxy

Example
a := "github/advanced-go/stdlib"

err := RegisterExchange("", nil)
fmt.Printf("test: RegisterExchange(_,nil) -> [err:%v]\n", err)

err = RegisterExchange(a, nil)
fmt.Printf("test: RegisterExchange(\"%v\",nil) -> [err:%v]\n", a, err)

err = RegisterExchange(a, appHttpExchange)
fmt.Printf("test: RegisterExchange(\"%v\",appHttpExchange) -> [err:%v]\n", a, err)

h := exchangeProxy.Lookup(a)
fmt.Printf("test: Lookup(\"%v\") -> [ok:%v]\n", a, h != nil)

err = RegisterExchange(a, appHttpExchange)
fmt.Printf("test: RegisterExchange(\"%v\",appHttpExchange) -> [err:%v]\n", a, err)
Output:

test: RegisterExchange(_,nil) -> [err:invalid argument: domain is empty]
test: RegisterExchange("github/advanced-go/stdlib",nil) -> [err:invalid argument: HTTP Exchange is nil for domain : [github/advanced-go/stdlib]]
test: RegisterExchange("github/advanced-go/stdlib",appHttpExchange) -> [err:<nil>]
test: Lookup("github/advanced-go/stdlib") -> [ok:true]
test: RegisterExchange("github/advanced-go/stdlib",appHttpExchange) -> [err:invalid argument: HTTP Exchange already exists for domain : [github/advanced-go/stdlib]]

func SetAuthExchange

func SetAuthExchange(h core.HttpExchange, ok func(int) bool)

func SetHostTimeout

func SetHostTimeout(d time.Duration)

func Startup

func Startup(duration time.Duration, resources ResourceMap) bool

Startup - templated function to start all registered resources.

Types

type ContentMap

type ContentMap map[string]map[string]string

ContentMap - slice of any content to be included in a message

type ResourceMap

type ResourceMap map[string]core.HttpExchange

Jump to

Keyboard shortcuts

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