Skip to content

michelemendel/goutils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Various functions that I use between projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published