xloadtype

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package xloadtype contains commonly used types for working with xload.Loader.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	Host string
	Port int
}

Endpoint represents a network endpoint It can be used to represent a target host:port pair.

Example
package main

import (
	"context"
	"fmt"

	"github.com/gojekfarm/xtools/xload"
	xloadtype "github.com/gojekfarm/xtools/xload/type"
)

var testValues = map[string]string{
	"LISTENER": "[::1]:8080",
	"ENDPOINT": "example.com:80",
}

var loader = xload.LoaderFunc(func(ctx context.Context, key string) (string, error) {
	return testValues[key], nil
})

func main() {
	type Server struct {
		Endpoint xloadtype.Endpoint `env:"ENDPOINT"`
	}

	var srv Server
	if err := xload.Load(context.Background(), &srv, loader); err != nil {
		panic(err)
	}

	fmt.Println(srv.Endpoint.String())

}
Output:

example.com:80

func (*Endpoint) Decode

func (e *Endpoint) Decode(v string) error

func (*Endpoint) String

func (e *Endpoint) String() string

type Listener

type Listener struct {
	IP   net.IP
	Port int
}

Listener represents a network listener, say, a tcp or http listener.

Example
package main

import (
	"context"
	"fmt"

	"github.com/gojekfarm/xtools/xload"
	xloadtype "github.com/gojekfarm/xtools/xload/type"
)

var testValues = map[string]string{
	"LISTENER": "[::1]:8080",
	"ENDPOINT": "example.com:80",
}

var loader = xload.LoaderFunc(func(ctx context.Context, key string) (string, error) {
	return testValues[key], nil
})

func main() {
	type Server struct {
		Listener xloadtype.Listener `env:"LISTENER"`
	}

	var srv Server
	if err := xload.Load(context.Background(), &srv, loader); err != nil {
		panic(err)
	}

	fmt.Println(srv.Listener.String())

}
Output:

[::1]:8080

func (*Listener) Decode

func (l *Listener) Decode(v string) error

func (*Listener) String

func (l *Listener) String() string

type URL

type URL url.URL

URL represents a URI reference.

URL is a type alias for url.URL. The general form represented is: [scheme:][//[userinfo@]host][/]path[?query][#fragment] See https://tools.ietf.org/html/rfc3986

func (*URL) Decode

func (u *URL) Decode(v string) error

func (*URL) Endpoint

func (u *URL) Endpoint() (*Endpoint, error)

Endpoint returns the endpoint of the URL. The URL host must be in the form of `host:port`.

func (*URL) String

func (u *URL) String() string

Jump to

Keyboard shortcuts

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