pkger/here/info.go

40 lines
707 B
Go
Raw Normal View History

2019-08-05 00:13:27 +03:00
package here
import (
"encoding/json"
)
// Info represents details about the directory/package
type Info struct {
2019-10-09 20:21:54 +03:00
Dir string
ImportPath string
Name string
Module Module
2019-10-09 20:21:54 +03:00
}
2019-11-10 13:56:09 +03:00
func (i Info) MarshalJSON() ([]byte, error) {
2019-10-09 20:21:54 +03:00
mm := map[string]interface{}{
2019-11-10 13:56:09 +03:00
"ImportPath": i.ImportPath,
"Name": i.Name,
"Module": i.Module,
"Dir": i.Dir,
}
2019-11-01 22:53:54 +03:00
return json.Marshal(mm)
2019-08-05 00:13:27 +03:00
}
// IsZero checks if the type has been filled
// with rich chocolately data goodness
func (i Info) IsZero() bool {
return i.String() == Info{}.String()
}
func (i Info) String() string {
b, err := json.MarshalIndent(i, "", " ")
if err != nil {
return err.Error()
}
s := string(b)
return s
}