common

package
v0.0.0-...-9f55086 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package common implements utility functions shared accross the application

Index

Examples

Constants

This section is empty.

Variables

View Source
var ConsoleBold = color.New(color.Bold).SprintFunc()

Console color varables

View Source
var ConsoleFailure = color.New(color.Bold, color.FgWhite, color.BgRed).SprintFunc()
View Source
var ConsoleInfo = color.New(color.Bold, color.FgWhite, color.BgCyan).SprintFunc()
View Source
var ConsoleSuccess = color.New(color.Bold, color.FgWhite, color.BgGreen).SprintFunc()
View Source
var ConsoleWarn = color.New(color.Bold, color.FgWhite, color.BgMagenta).SprintFunc()

Functions

func PrettyPrintJSONToConsole

func PrettyPrintJSONToConsole(b []byte)

Pretty print JSON to console for debugging

Only active if debug is true in the .env file:

DEBUG=true
Example
package main

import (
	"encoding/json"

	"github.com/mwiater/golangdocker/common"
)

func main() {
	testSlice := []string{"one", "one", "two", "two", "three", "three"}
	testSlice1 := common.UniqueSlice(testSlice)
	testSlice2, _ := json.Marshal(testSlice1)
	common.PrettyPrintJSONToConsole(testSlice2)
}
Output:

[
	"one",
	"two",
	"three"
]

func SplitStringLines

func SplitStringLines(s string) []string

Return slice with each line of a multi-line string, splitting on '\n'

Example
package main

import (
	"fmt"

	"github.com/mwiater/golangdocker/common"
)

func main() {
	testString := "line 01\nline 02\nline 03"
	fmt.Println(common.SplitStringLines(testString))
}
Output:

[line 01 line 02 line 03]

func UniqueSlice

func UniqueSlice(s []string) []string

Return slice with duplicate items removed

Example
package main

import (
	"fmt"

	"github.com/mwiater/golangdocker/common"
)

func main() {
	testSlice := []string{"one", "one", "two", "two", "three", "three"}
	fmt.Println(common.UniqueSlice(testSlice))
}
Output:

[one two three]

Types

This section is empty.

Jump to

Keyboard shortcuts

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