Last active
March 8, 2022 16:08
-
-
Save xvbnm48/0d15a2c4b3401127660c7feb6e78b667 to your computer and use it in GitHub Desktop.
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 ( | |
| "errors" | |
| "fmt" | |
| "strconv" | |
| "strings" | |
| ) | |
| func validate(input string) (bool, error) { | |
| if strings.TrimSpace(input) == "" { | |
| return false, errors.New("cannot be empty") | |
| } | |
| return true, nil | |
| } | |
| func main(){ | |
| var anime string | |
| fmt.Println("enter your favorite anime ") | |
| fmt.Scanln(&anime) | |
| if valid, err := validate(anime); valid { | |
| fmt.Println("favorite anime is ", anime) | |
| } else { | |
| panic(err.Error()) | |
| } | |
| } | |
| // jika salah | |
| // enter your favorite anime | |
| // | |
| //error eccured cannot be empty | |
| // saya tidak mengisi maka program error dan stop | |
| // jika benar makaa program akan lanjut berjalan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment