Skip to content

Instantly share code, notes, and snippets.

@xvbnm48
Last active March 8, 2022 16:08
Show Gist options
  • Select an option

  • Save xvbnm48/0d15a2c4b3401127660c7feb6e78b667 to your computer and use it in GitHub Desktop.

Select an option

Save xvbnm48/0d15a2c4b3401127660c7feb6e78b667 to your computer and use it in GitHub Desktop.
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