common

package module
v0.2.71 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: BSD-3-Clause Imports: 26 Imported by: 28

README

go-common

Documentation

Overview

Copyright © 2025 Matt Krueger <[email protected]> All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const DEFAULT_DISABLE_KEEPALIVES = false
View Source
const DEFAULT_IDLE_CONN_TIMEOUT = 5
View Source
const Version = "0.2.71"

Variables

View Source
var ConfirmAcceptMessage = "Proceeding"
View Source
var ConfirmRejectMessage = "Cowardly refused"
View Source
var LogFile *os.File

Functions

func AppendConfig added in v0.2.37

func AppendConfig(filename string) error

func CheckErr added in v0.1.24

func CheckErr(err error)

func CobraAddCommand added in v0.1.30

func CobraAddCommand(cobraRootCmd, parentCmd, cobraCmd CobraCommand)

call from non-root cobra command init

func CobraInit added in v0.1.26

func CobraInit(cobraRootCmd CobraCommand)

call from root cobra command init

func ConfigDir added in v0.2.32

func ConfigDir() string

func ConfigEdit added in v0.1.26

func ConfigEdit()

func ConfigInit added in v0.1.26

func ConfigInit(allowClobber bool) string

func ConfigString added in v0.1.26

func ConfigString(header bool) string

func Confirm

func Confirm(prompt string) bool

func Expand

func Expand(value string) string

func Fatal added in v0.1.13

func Fatal(err error) error

use a local function alias to get the source mapping right

func Fatalf added in v0.1.14

func Fatalf(format string, args ...interface{}) error

func FormatJSON

func FormatJSON(v any) string

func FormatYAML added in v0.2.30

func FormatYAML(value any) string

func GetHostnameDetail added in v0.2.45

func GetHostnameDetail() (string, string, string, error)

func HexDump added in v0.1.12

func HexDump(data []byte) string

func HostDomain added in v0.2.41

func HostDomain() (string, error)

func HostFQDN added in v0.2.41

func HostFQDN() (string, error)

func HostShortname added in v0.2.41

func HostShortname() (string, error)

func Init added in v0.1.2

func Init(name, version, configFile string)

call Init if not using cobra

func IsDir

func IsDir(path string) bool

func IsFile

func IsFile(pathname string) bool

func OptionInt added in v0.2.23

func OptionInt(cobraCmd CobraCommand, name, flag string, defaultValue int, description string)

func OptionKey added in v0.1.26

func OptionKey(cobraCmd CobraCommand, key string) string

func OptionString added in v0.1.26

func OptionString(cobraCmd CobraCommand, name, flag, defaultValue, description string)

func OptionStringSlice added in v0.2.35

func OptionStringSlice(cobraCmd CobraCommand, name, flag string, defaultValue []string, description string)

func OptionSwitch added in v0.1.26

func OptionSwitch(cobraCmd CobraCommand, name, flag, description string)

func ProgramName

func ProgramName() string

func ProgramVersion added in v0.1.2

func ProgramVersion() string

func Shutdown added in v0.1.31

func Shutdown()

call Shutdown at exit if not using cobra

func TildePath added in v0.1.26

func TildePath(path string) (string, error)

func ViperGet added in v0.2.22

func ViperGet(key string) any

func ViperGetBool

func ViperGetBool(key string) bool

func ViperGetInt

func ViperGetInt(key string) int

func ViperGetInt64

func ViperGetInt64(key string) int64

func ViperGetString

func ViperGetString(key string) string

func ViperGetStringMap added in v0.2.70

func ViperGetStringMap(key string) map[string]any

func ViperGetStringMapString added in v0.2.19

func ViperGetStringMapString(key string) map[string]string

func ViperGetStringSlice added in v0.1.11

func ViperGetStringSlice(key string) []string

func ViperKey added in v0.0.7

func ViperKey(key string) string

func ViperSet

func ViperSet(key string, value any)

func ViperSetDefault

func ViperSetDefault(key string, value any)

func Warning added in v0.1.13

func Warning(format string, args ...interface{})

Types

type APIClient added in v0.2.3

type APIClient interface {
	Close()
	Get(path string, response interface{}) (string, error)
	Post(path string, request, response interface{}, headers *map[string]string) (string, error)
	Put(path string, request, response interface{}, headers *map[string]string) (string, error)
	Delete(path string, response interface{}) (string, error)
	SetFlag(string, bool) error
	StatusCode() (int, bool)
}

func NewAPIClient added in v0.2.3

func NewAPIClient(prefix, url, certFile, keyFile, caFile string, headers *map[string]string) (APIClient, error)

type CobraCommand added in v0.1.30

type CobraCommand interface {
}

type Sendmail added in v0.1.19

type Sendmail interface {
	Send(to, from, subject string, body []byte) error
}

func NewSendmail added in v0.1.27

func NewSendmail(hostname string, port int, username, password, CAFile string) (Sendmail, error)

type SendmailClient added in v0.1.29

type SendmailClient struct {
	Host     string
	Port     int
	Username string
	Password string
	CAFile   string
	// contains filtered or unexported fields
}

func (*SendmailClient) Send added in v0.1.29

func (c *SendmailClient) Send(to, from, subject string, body []byte) error

Jump to

Keyboard shortcuts

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