go_common_lib

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: MIT Imports: 11 Imported by: 5

README

Go common lib

Security Rating Bugs Code Smells Coverage

Tis module used as smaple module for most popular func.

ENV parameters

  • N/a

File parameters application.yml

  • N/a

Lint, Test & Coverage

  1. Install linter

    go install github.com/golangci/golangci-lint/cmd/golangci-lint
    

    run check

    golangci-lint run  > checkstyle.xml
    
  2. Run test

    go test -v -coverpkg=./... -coverprofile=profile.cov ./... -json > test_report.json
    
  3. Coverage

    go tool cover -func profile.cov
    

Methods

Method Description Params Result
SliceContain A function to check slice contain item string slice []string, item string bool
UpdateList A function for update exist slice not contain item string slice []string, item string []string
StringFromList A function convert slice to sting list []string st string
UpdateStructList A function for update exist slice values from anothe slice main []string, in []string []string
CalcHash A function for calculate string hash sum by sha256 aStr string string
SortedMap A function for sort slice map's m []map[string]string out []map[string]string
ListConvert A function for convert interface to slice strings in interface{} []string, error
UpdateMapList A function for update slince map by not exist map sliceMaps []map[string]string, itemMap map[string]string []map[string]string
StandardizeSpaces A function for trim first & last space s string string
UpdateListBySplit A function for update slice string by splited values use slice spliters string slice []string, item string, spliters []string []string
MapListConvert A function for convert interface to slice map in interface{} []map[string]string, error

Documentation

Overview

Package go_common_lib is a simple Go module used as smaple module for most popular func.

See README.md for more info.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	Log = logging.Log
)

Functions

func CalcHash

func CalcHash(aStr string) string

A function for calculate string hash sum by sha256 The return value is hash string

Example

Example generate hash string for string data

result := CalcHash("testString")
fmt.Println("Hash:", result)
Output:

Hash: 4acf0b39d9c4766709a3689f553ac01ab550545ffa4544dfc0b2cea82fba02a3

func CheckStingSliceContain added in v1.0.5

func CheckStingSliceContain(ctx context.Context, slice []string, item string) bool

A function to check slice contain item string The return value is bool

func ConvertInterfaceToSliceMapString added in v1.0.4

func ConvertInterfaceToSliceMapString(ctx context.Context, in interface{}) ([]map[string]string, error)

A function for convert interface to slice map The return value is slice map or error

func ConvertInterfaceToSliceString added in v1.0.4

func ConvertInterfaceToSliceString(ctx context.Context, t interface{}) ([]string, error)

A function for convert interface to slice strings The return value is slice strings

func DecodeInterfaceToInterface added in v1.0.4

func DecodeInterfaceToInterface(ctx context.Context, data interface{}, out interface{}) error

A function for decode one interface values to anothe The return set multi atributes to span

func GetStringHash added in v1.0.4

func GetStringHash(ctx context.Context, aStr string) string

A function for calculate string hash sum by sha256 The return value is hash string

func ListConvert

func ListConvert(in interface{}) ([]string, error)

A function for convert interface to slice strings The return value is slice strings

Example

Example convert interface to slice strings

var in interface{}
in = []string{"first", "second"}
result, _ := ListConvert(in)
fmt.Println("Slice:", result)
Output:

Slice: [first second]

func MapListConvert

func MapListConvert(in interface{}) ([]map[string]string, error)

A function for convert interface to slice map The return value is slice map or error

Example

Example convert slice map string to string

var names interface{}
names = []map[string]string{{"first": "second"}}
result, _ := MapListConvert(names)
fmt.Println("String:", result)
Output:

String: [map[first:second]]

func SliceContain

func SliceContain(slice []string, item string) bool

A function to check slice contain item string The return value is bool

Example

Example check slice contain value

result := SliceContain([]string{"a", "b", "c"}, "b")
fmt.Println("Contain:", result)
Output:

Contain: true

func SortedMap

func SortedMap(m []map[string]string) (out []map[string]string)

A function for sort slice map`s The return value is sorted slice

Example

Example sort slice map string by key

result := SortedMap([]map[string]string{{"b": "c", "c": "c", "a": "c"}})
fmt.Println("Sorted map:", result)
Output:

Sorted map: [map[a:c] map[b:c] map[c:c]]

func SortedSliceMapString added in v1.0.4

func SortedSliceMapString(ctx context.Context, m []map[string]string) []map[string]string

A function for sort slice map`s The return value is sorted slice

func SpanSetAttribute added in v1.0.4

func SpanSetAttribute(sp trace.Span, prefix string, attributs interface{})

A function for set multi atributes to span The return set multi atributes to span

func StandardizeSpaces

func StandardizeSpaces(s string) string

A function for trim first & last space The return value is trimed string

Example

Example strip first and last spaces

result := StandardizeSpaces(" ggg ggg ggg ")
fmt.Println("String:", result)
Output:

String: ggg ggg ggg

func StringFromList

func StringFromList(list []string) (st string)

A function convert slice to sting The return value is string

Example

Example convert slice to string

result := StringFromList([]string{"a", "b", "c"})
fmt.Println("String:", result)
Output:

String: a,b,c

func StringFromStingSlice added in v1.0.5

func StringFromStingSlice(ctx context.Context, list []string) (st string)

A function convert slice to sting The return value is string

func TrimString added in v1.0.5

func TrimString(ctx context.Context, s string) string

A function for trim first & last space The return value is trimed string

func UpdateList

func UpdateList(slice []string, item string) []string

A function for update exist slice not contain item string The return value is new slice

Example

Example update string slice add new value if not contain

result := UpdateList([]string{"a", "b", "c"}, "d")
fmt.Println("New slice:", result)
Output:

New slice: [a b c d]

func UpdateListBySplit

func UpdateListBySplit(slice []string, item string, spliters []string) []string

A function for update slice string by splited values use slice spliters string The return value is slice strings

Example

Example update slice string values by splited data

result := UpdateListBySplit([]string{"A", "B"}, "B*C", []string{"*"})
fmt.Println("String:", result)
Output:

String: [A B C]

func UpdateMapList

func UpdateMapList(sliceMaps []map[string]string, itemMap map[string]string) []map[string]string

A function for update slince map by not exist map The return value is updated slice

Example

Example update map string slice by anothe add new data or value

result := UpdateMapList([]map[string]string{{"a": "b"}}, map[string]string{"b": "b"})
fmt.Println("Slice:", result)
Output:

Slice: [map[a:b] map[b:b]]

func UpdateSliceMapStringFromMapString added in v1.0.4

func UpdateSliceMapStringFromMapString(ctx context.Context, sliceMaps []map[string]string, itemMap map[string]string) []map[string]string

A function for update slince map by not exist map The return value is updated slice

func UpdateStingSlice added in v1.0.4

func UpdateStingSlice(ctx context.Context, slice []string, item string) []string

A function for update exist slice not contain item string The return value is new slice

func UpdateStingSliceBySplit added in v1.0.5

func UpdateStingSliceBySplit(ctx context.Context, slice []string, item string, spliters []string) []string

A function for update slice string by splited values use slice spliters string The return value is slice strings

func UpdateStingSliceFromStingSlice added in v1.0.4

func UpdateStingSliceFromStingSlice(ctx context.Context, main []string, in []string) []string

A function for update exist slice values from anothe slice The return value is updated slice

func UpdateStructList

func UpdateStructList(main []string, in []string) []string

A function for update exist slice values from anothe slice The return value is updated slice

Example

Example update string slice by anothe string slice add not contain datas

result := UpdateStructList([]string{"a", "b"}, []string{"a", "c"})
fmt.Println("Updated slice:", result)
Output:

Updated slice: [a b c]

Types

This section is empty.

Jump to

Keyboard shortcuts

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