Skip to content

Instantly share code, notes, and snippets.

@SeptiyanAndika
Last active October 5, 2018 08:16
Show Gist options
  • Save SeptiyanAndika/eee67c887eb0ae49503e9776999f2e3a to your computer and use it in GitHub Desktop.
Save SeptiyanAndika/eee67c887eb0ae49503e9776999f2e3a to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
)
type CurrencySchema struct {
Code string
Name string
Type string
}
type CRUDInterface interface {
Model() (interface{}, interface{})
}
type CRUD struct {
CRUDInterface
Model func() (interface{}, interface{})
}
func (cr CRUD) Create(data string) {
fmt.Println("create function");
m, _:=cr.Model()
fmt.Println(reflect.TypeOf(m).Name());
fmt.Println(data);
}
func (cr CRUD) GET() {
fmt.Println("Get function");
}
type CurrencyRepository struct {
CRUD
}
func main() {
cr := CurrencyRepository{};
cr.Model = func() (interface{}, interface{}) { return CurrencySchema{}, []CurrencySchema{} }
cr.Create("ini data")
fmt.Println("=====")
cr.GET()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment