Skip to content

Instantly share code, notes, and snippets.

@madflojo
Created February 14, 2021 18:29
Show Gist options
  • Save madflojo/6bcc2c567612a7830400889ee3dff5ab to your computer and use it in GitHub Desktop.
Save madflojo/6bcc2c567612a7830400889ee3dff5ab to your computer and use it in GitHub Desktop.
Interface Article - PowerLevel.go
package main
import (
"fmt"
)
type Database interface {
Fetch(key string) (int, error)
}
var DB Database
func isOver9000() bool {
i, err := DB.Fetch("powerlevel")
if err != nil {
// if this were a real program, this should return an error
// but this is an example, so it's ok.
return false
}
if i > 9000 {
return true
}
return false
}
func main() {
if isOver9000() {
fmt.Println("It's over 9000!!!")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment