Created
February 14, 2021 18:29
-
-
Save madflojo/6bcc2c567612a7830400889ee3dff5ab to your computer and use it in GitHub Desktop.
Interface Article - PowerLevel.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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