Skip to content

Instantly share code, notes, and snippets.

@focusj
Created November 2, 2023 03:11
Show Gist options
  • Save focusj/abd262c363e1dcecc8534b19af14e96a to your computer and use it in GitHub Desktop.
Save focusj/abd262c363e1dcecc8534b19af14e96a to your computer and use it in GitHub Desktop.
how to use golang type alias for map
package main
import (
"fmt"
)
type TemplateCacheAlias map[string]int
func (t *TemplateCacheAlias) Get(name string) int {
return (*t)[name]
}
func (t *TemplateCacheAlias) Set(name string, num int) error {
(*t)[name] = num
return nil
}
func main() {
fmt.Println("Hello, playground")
t := TemplateCacheAlias{}
t.Set("something", 2)
fmt.Printf("value : %d", t.Get("something"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment