Compare commits
No commits in common. "6b17bec30c78274cb2761465cc09fc503afdf3d3" and "8143c2d08a391d21b1448cd999da2dd5e40c0338" have entirely different histories.
6b17bec30c
...
8143c2d08a
21
env/env.go
vendored
21
env/env.go
vendored
@ -1,21 +0,0 @@
|
|||||||
package env
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Env() {
|
|
||||||
os.Setenv("GOBYEXAMPLE", "WORKS")
|
|
||||||
fmt.Println("$GOBYEXAMPLE=", os.Getenv("GOBYEXAMPLE"))
|
|
||||||
envGoRoot := os.Getenv("GOROOT")
|
|
||||||
fmt.Println("$GOROOT=", envGoRoot)
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println("All env vars:")
|
|
||||||
for _, envLine := range os.Environ() {
|
|
||||||
pair := strings.SplitN(envLine, "=", 2)
|
|
||||||
fmt.Printf("%s=%s\n", pair[0], pair[1])
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,42 +0,0 @@
|
|||||||
package logging
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"log/slog"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Logging() {
|
|
||||||
log.Println("Baby's first log!")
|
|
||||||
|
|
||||||
log.SetFlags(log.LstdFlags | log.Lmicroseconds)
|
|
||||||
log.Println("Log with microseconds!")
|
|
||||||
|
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
|
||||||
log.Println("Now with filename!")
|
|
||||||
|
|
||||||
mlog := log.New(os.Stdout, "[mlog] ", log.LstdFlags|log.Lshortfile)
|
|
||||||
mlog.Println("My own logger!")
|
|
||||||
|
|
||||||
mlog.SetPrefix("[mlog with SetPrefix] ")
|
|
||||||
mlog.Println("Changed prefix")
|
|
||||||
|
|
||||||
var logBuffer bytes.Buffer
|
|
||||||
buflog := log.New(&logBuffer, "[bytes] ", log.LstdFlags|log.Lshortfile)
|
|
||||||
|
|
||||||
buflog.Println("Writing to a bytes buffer")
|
|
||||||
buflog.Println("Writing more to the bytes buffer")
|
|
||||||
|
|
||||||
fmt.Println()
|
|
||||||
fmt.Println("Printing logs from bytes buffer below:")
|
|
||||||
fmt.Println(logBuffer.String())
|
|
||||||
|
|
||||||
jsonHandler := slog.NewJSONHandler(os.Stderr, nil)
|
|
||||||
jlog := slog.New(jsonHandler)
|
|
||||||
jlog.Info("First json log entry")
|
|
||||||
jlog.Info("kv args", "key1", 1, "key2", 2, "key3", true)
|
|
||||||
jlog.Warn("warning!!!")
|
|
||||||
jlog.Error("error!!!")
|
|
||||||
}
|
|
8
main.go
8
main.go
@ -43,9 +43,7 @@ import (
|
|||||||
// "git.sangeeth.dev/gobyexample/tmp"
|
// "git.sangeeth.dev/gobyexample/tmp"
|
||||||
// "git.sangeeth.dev/gobyexample/embed"
|
// "git.sangeeth.dev/gobyexample/embed"
|
||||||
// "git.sangeeth.dev/gobyexample/cli"
|
// "git.sangeeth.dev/gobyexample/cli"
|
||||||
// "git.sangeeth.dev/gobyexample/subcmd"
|
"git.sangeeth.dev/gobyexample/subcmd"
|
||||||
// "git.sangeeth.dev/gobyexample/env"
|
|
||||||
"git.sangeeth.dev/gobyexample/logging"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -91,7 +89,5 @@ func main() {
|
|||||||
// tmp.Tmp()
|
// tmp.Tmp()
|
||||||
// embed.Embed()
|
// embed.Embed()
|
||||||
// cli.Cli()
|
// cli.Cli()
|
||||||
// subcmd.SubCmd()
|
subcmd.SubCmd()
|
||||||
// env.Env()
|
|
||||||
logging.Logging()
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user