Created
December 9, 2021 04:52
-
-
Save incfly/12f3ab66d7abc2fbbc3a32fc65e22c43 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Config struct { | |
name string | |
} | |
type translator func(arg ...interface{}) *Config | |
func wrapper(tr translator, arg ...interface{}) { | |
out := tr(arg...) | |
for _, a := range arg { | |
fmt.Printf("mapping from %v -> %v\n", a, out) | |
} | |
} | |
func translateInteger(a ...interface{}) *Config { | |
return &Config{ | |
name: fmt.Sprintf("%v-%v", a[0], a[1]), | |
} | |
} | |
func translateSingle(a int) *Config { | |
return nil | |
} | |
func translateTwo(a, b int) *Config { | |
return nil | |
} | |
func wraqq(f interface{}, a ...int) { | |
f1, ok := f.(func(int) *Config) | |
if ok { | |
f1(a[0]) | |
} | |
f2, ok := f.(func(int, int) *Config) | |
if ok { | |
f2(a[0], a[1]) | |
} | |
} | |
func checkq(g interface{}) { | |
_, ok := g.(func(int, int) *Config) | |
fmt.Println("ok or not ", ok) | |
} | |
func main() { | |
f := translateInteger | |
wrapper(f, 3, 4) | |
wraqq(translateTwo, 2, 1) | |
checkq(translateSingle) | |
checkq(translateTwo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment