structure utils
Provides convenience functions on structures.
package main
import (
"log""github.com/go-utils/structs"
)
type (
Repository1struct{}
Repository2struct{}
Repository3struct{}
)
typeServiceRepositoriesstruct {
Repository1*Repository1Repository2*Repository2Repository3*Repository3
}
typeServicestruct {
reposServiceRepositories
}
funcNewService(reposServiceRepositories) *Service {
ifnilFields:=structs.GetNilFields(repos); len(nilFields) >0 {
log.Fatalf("%+v", nilFields)
// Output: ["ServiceRepositories.Repository2", "ServiceRepositories.Repository3"]
}
return&Service{repos: repos}
}
funcmain() {
repos:=ServiceRepositories{
Repository1: new(Repository1),
}
service:=NewService(repos)
...
}package main
import (
"fmt""log""github.com/go-utils/structs"
)
typeHogestruct{}
funcmain() {
hoge:=new(Hoge)
hogeName:=structs.GetStructName(hoge)
fmt.Printf("struct name: %#v\n", hogeName)
// Output: "Hoge"
}- Under the MIT License
- Copyright (C) 2022 go-utils