package main import "fmt" import "log" import "os" import "strings" var users = map[string]map[string]string{ "meutel": map[string]string{ "avatar_url": "https://git.meutel.net/avatars/1", "full_name": "Meutel", }, "ARCHIVES": map[string]string{ "avatar_url": "https://git.meutel.net/avatars/2", }, } const defaultAvatar = "https://git.meutel.net/img/avatar_default.png" func avatarUrl(username string) string { if url, ok := users[username]["avatar_url"]; ok { return url } else { return defaultAvatar } } func fullName(username string) (string, bool) { if user, ok := users[username]; ok { if name, ok2 := user["full_name"]; ok2 { return name, true } else { return username, true } } else { return "Unknown", false } } func main() { if len(os.Args) < 2 { log.Fatalln("Needs user name argument") } name := os.Args[1] // avatarId := 1 html := ` Profile

{{ name }}

` full, exists := fullName(name) if !exists { fmt.Fprintln(os.Stderr, "Unknown user "+name) } html = strings.Replace(html, "{{ name }}", full, 1) html = strings.Replace(html, "{{ avatarUrl }}", avatarUrl(name), 1) fmt.Println(html) }