Skip to content

otiai10/ternary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ternary

Build Status

Ternary expression for golang, to enjoy code-golf ⛳

port := ternary.String(os.Getenv("PORT"))("8080")
// Returns "8080" if "PORT" == ""

why

If you want

status := 500
if flag {
    status = 200
}

Write

status := ternary.If(flag).Int(200, 500)

If you want

res := map[string]interface{}{
    "user":       user,
    "expired_at": nil,
}
if user.Expire() {
    res["expire_at"] = time.Now()
}
json.NewEncoder(wr).Encode(res)

Write

json.NewEncoder(wr).Encode(map[string]interface{}{
    "user":       user,
    "expired_at": ternary.If(user.Expire()).Interface(time.Now(), nil),
})

Enjoy ⛳ !

About

Golang ternary expression ⛳

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages