pkger/here/module.go

56 lines
991 B
Go
Raw Permalink Normal View History

2019-08-05 00:13:27 +03:00
package here
2019-10-09 20:21:54 +03:00
import (
"encoding/json"
2019-10-16 17:24:05 +03:00
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa"
"github.com/markbates/pkger/internal/takeon/github.com/markbates/hepa/filters"
2019-10-09 20:21:54 +03:00
)
2019-08-05 00:13:27 +03:00
type Module struct {
2019-10-09 20:21:54 +03:00
Path string
Main bool
Dir string
GoMod string
GoVersion string
}
func (m Module) MarshalJSON() ([]byte, error) {
mm := map[string]interface{}{
"Main": m.Main,
"GoVersion": m.GoVersion,
}
hep := hepa.New()
hep = hepa.With(hep, filters.Home())
hep = hepa.With(hep, filters.Golang())
cm := map[string]string{
"Path": m.Path,
"Dir": m.Dir,
"GoMod": m.GoMod,
}
for k, v := range cm {
b, err := hep.Filter([]byte(v))
if err != nil {
return nil, err
}
mm[k] = string(b)
}
return json.Marshal(mm)
2019-08-05 00:13:27 +03:00
}
func (i Module) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
return string(b)
}
func (i Module) IsZero() bool {
return i.String() == Module{}.String()
}