Created
November 2, 2023 03:11
-
-
Save focusj/abd262c363e1dcecc8534b19af14e96a to your computer and use it in GitHub Desktop.
how to use golang type alias for map
This file contains 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 ( | |
"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