Something went wrong. Try again.
Fork of micro-editor/micro
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647package config
import ( "errors"
"github.com/micro-editor/json5")
var ( ErrMissingName = errors.New("Missing or empty name field") ErrMissingDesc = errors.New("Missing or empty description field") ErrMissingSite = errors.New("Missing or empty website field"))
// PluginInfo contains all the needed info about a plugin// The info is just strings and are not used beyond that (except// the Site and Install fields should be valid URLs). This means// that the requirements for example can be formatted however the// plugin maker decides, the fields will only be parsed by humans// Name: name of plugin// Desc: description of plugin// Site: home website of plugin// Install: install link for plugin (can be link to repo or zip file)// Vstr: version// Require: list of dependencies and requirementstype PluginInfo struct { Name string `json:"Name"` Desc string `json:"Description"` Site string `json:"Website"`}
// NewPluginInfo parses a JSON input into a valid PluginInfo struct// Returns an error if there are any missing fields or any invalid fields// There are no optional fields in a plugin info json filefunc NewPluginInfo(data []byte) (*PluginInfo, error) { var info []PluginInfo
if err := json5.Unmarshal(data, &info); err != nil { return nil, err } if len(info) == 0 || info[0].Name == "" { return nil, ErrMissingName }
return &info[0], nil}