goutils

command module
v0.0.0-...-9e56bd4 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: MIT Imports: 6 Imported by: 0

README

goutils

Various functions that I use in projects


Logging

Using

Levels

  • Debug
  • Info
  • Warn
  • Error
  • DPanic
  • Panic

Init

var lg *zap.SugaredLogger

func init() {
	lg = log.InitWithConsole(zapcore.DebugLevel)
}

Set level

lg = log.SetDebugLevel()

lg = log.SetInfoLevel()

etc...

Log

  • Simple: log.Info("hello")
  • Formatted: log.Infof("hello %s", "world")
  • Structured: log.Infow("hello", "var1", 12, "var2", 24)

Time

time.StampTimeNow()

returns time in RFC3339Nano

ex: 2023-04-27T11:33:45.772006+02:00


Network

Get local IP network.GetIP()


Pretty Print

Only tried on simple structs

Pretty print a struct

pp.PP(someStruct)

Return a pretty struct

struct, err := pp.PrettyStruct(someStruct)


UUID

uuid.GenerateUUID()

Get a UUID using KSUID, https://github.com/segmentio/ksuid

Why this one?

Because someone said it was good, see https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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