bandaid

package module
v0.0.0-...-dd2cae1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

README

Band Aid

A collection of utilities we use in our golang projects. Try and minimize the non standard library dependencies, if possible.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Container = &IoCContainer{
		objects: make(map[ObjectID]interface{}),
	}
)

Functions

func ChangeExt

func ChangeExt(filename string, newExt string) string

func ConfigDir

func ConfigDir() string

func CopyFile

func CopyFile(src, dst string) error

func DeleteFile

func DeleteFile(path string) error

func DirExists

func DirExists(dir string) bool

func DownloadFile

func DownloadFile(filepath string, url string) error

func ExpandEnvVars

func ExpandEnvVars(ctx context.Context, value string) (string, error)

func ExpandTilde

func ExpandTilde(path string) string

func FileExists

func FileExists(filename string) bool

func FileSize

func FileSize(filename string) (int64, error)

func GetInt

func GetInt(value string, defaultValue int) int

func GetIntf

func GetIntf(value string, defaultFunc func() int) int

func GetMacAddr

func GetMacAddr() ([]string, error)

func HomeDir

func HomeDir() string

func HttpGetWithTimeout

func HttpGetWithTimeout(url string, timeout time.Duration, headers map[string]string) (*http.Response, error)

func PrintRequest

func PrintRequest(r *http.Request)

func PrintResponse

func PrintResponse(r *http.Response)

func StringInSlice

func StringInSlice(a string, list []string) bool

func StripPort

func StripPort(hostport string) string

func TrimExt

func TrimExt(path string) string

func TruncateString

func TruncateString(str string, num int) string

Types

type AtomBool

type AtomBool struct {
	// contains filtered or unexported fields
}

AtomBool is a thread safe atomic boolean

func (*AtomBool) Get

func (b *AtomBool) Get() bool

Get the value of the bool

func (*AtomBool) Set

func (b *AtomBool) Set(value bool)

Set the value for the bool

type IPInfo

type IPInfo struct {
	Address    string `json:"address"`
	Source     string `json:"source"`
	IsFallback bool   `json:"is_fallback"`

	HasCity bool `json:"has_city"`
	City    struct {
		GeoNameID uint              `json:"geoname_id"`
		Names     map[string]string `json:"names"`
	} `json:"city"`
	Continent struct {
		Code      string            `json:"code"`
		GeoNameID uint              `json:"geoname_id"`
		Names     map[string]string `json:"names"`
	} `json:"continent"`
	Country struct {
		GeoNameID         uint              `json:"geoname_id"`
		IsInEuropeanUnion bool              `json:"is_in_european_union"`
		IsoCode           string            `json:"iso_code"`
		Names             map[string]string `json:"names"`
	} `json:"country"`
	Location struct {
		AccuracyRadius uint16  `json:"accuracy_radius"`
		Latitude       float64 `json:"latitude"`
		Longitude      float64 `json:"longitude"`
		MetroCode      uint    `json:"metro_code"`
		TimeZone       string  `json:"time_zone"`
	} `json:"location"`
	Postal struct {
		Code string `json:"code"`
	} `json:"postal"`
	RegisteredCountry struct {
		GeoNameID         uint              `json:"geoname_id"`
		IsInEuropeanUnion bool              `json:"is_in_european_union"`
		IsoCode           string            `json:"iso_code"`
		Names             map[string]string `json:"names"`
	} `json:"registered_country"`
	RepresentedCountry struct {
		GeoNameID         uint              `json:"geoname_id"`
		IsInEuropeanUnion bool              `json:"is_in_european_union"`
		IsoCode           string            `json:"iso_code"`
		Names             map[string]string `json:"names"`
		Type              string            `json:"type"`
	} `json:"represented_country"`
	Subdivisions []struct {
		GeoNameID uint              `json:"geoname_id"`
		IsoCode   string            `json:"iso_code"`
		Names     map[string]string `json:"names"`
	} `json:"subdivisions"`
	Traits struct {
		IsAnonymousProxy    bool `json:"is_anonymous_proxy"`
		IsSatelliteProvider bool `json:"is_satellite_provider"`
	} `json:"traits"`

	HasASN bool `json:"has_asn"`
	ASN    struct {
		AutonomousSystemNumber       uint   `json:"autonomous_system_number"`
		AutonomousSystemOrganization string `json:"autonomous_system_organization"`
	} `json:"asn"`

	HasAnonymousIP bool `json:"has_anonymous_ip"`
	AnonymousIP    struct {
		IsAnonymous       bool `json:"is_anonymous"`
		IsAnonymousVPN    bool `json:"is_anonymous_vpn"`
		IsHostingProvider bool `json:"is_hosting_provider"`
		IsPublicProxy     bool `json:"is_public_proxy"`
		IsTorExitNode     bool `json:"is_tor_exit_node"`
	} `json:"anonymous_ip"`
}

type IPSource

type IPSource string

type IPType

type IPType int

type IoCContainer

type IoCContainer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*IoCContainer) Assign

func (c *IoCContainer) Assign(ctx context.Context, name ObjectID, obj interface{}) error

func (*IoCContainer) Clear

func (c *IoCContainer) Clear(ctx context.Context)

func (*IoCContainer) Fetch

func (c *IoCContainer) Fetch(ctx context.Context, name ObjectID) interface{}

type ObjectID

type ObjectID string

Jump to

Keyboard shortcuts

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