Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 786 Bytes

README.md

File metadata and controls

51 lines (38 loc) · 786 Bytes

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 ⛳ !