Skip to content

Instantly share code, notes, and snippets.

@alileza
Created December 29, 2016 14:39
Show Gist options
  • Save alileza/e80349466464cece131170c66528e01e to your computer and use it in GitHub Desktop.
Save alileza/e80349466464cece131170c66528e01e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"strings"
)
func main() {
args := os.Args[1:]
if len(args) == 0 {
log.Fatal("argument is needed")
}
file, err := ioutil.ReadFile(args[0])
if err != nil {
log.Fatal(err)
}
commands := strings.Split(string(file), "\n")
for _, command := range commands {
cmd := strings.Split(command, " ")
switch cmd[0] {
case "makan":
makan(cmd[1])
case "mandi":
mandi(cmd[1], cmd[2])
}
}
}
func makan(args string) {
fmt.Println("Makan ", args)
}
func mandi(kapan, dimana string) {
fmt.Println("Mandi ", kapan, " di ", dimana)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment