github.com/qri-io/qri@v0.10.1-0.20220104210721-c771715036cb/config/repo.go (about) 1 package config 2 3 import ( 4 "github.com/qri-io/jsonschema" 5 ) 6 7 // Repo configures a qri repo 8 type Repo struct { 9 Type string `json:"type"` 10 Path string `json:"path,omitempty"` 11 } 12 13 // SetArbitrary is an interface implementation of base/fill/struct in order to safely 14 // consume config files that have definitions beyond those specified in the struct. 15 // This simply ignores all additional fields at read time. 16 func (cfg *Repo) SetArbitrary(key string, val interface{}) error { 17 return nil 18 } 19 20 // DefaultRepo creates & returns a new default repo configuration 21 func DefaultRepo() *Repo { 22 return &Repo{ 23 Type: "fs", 24 } 25 } 26 27 // Validate validates all fields of repo returning all errors found. 28 func (cfg Repo) Validate() error { 29 schema := jsonschema.Must(`{ 30 "$schema": "http://json-schema.org/draft-06/schema#", 31 "title": "Repo", 32 "description": "Config for the qri repository", 33 "type": "object", 34 "required": ["type"], 35 "properties": { 36 "type": { 37 "description": "Type of repository", 38 "type": "string", 39 "enum": [ 40 "fs", 41 "mem" 42 ] 43 } 44 } 45 }`) 46 return validate(schema, &cfg) 47 } 48 49 // Copy returns a deep copy of the Repo struct 50 func (cfg *Repo) Copy() *Repo { 51 res := &Repo{ 52 Type: cfg.Type, 53 } 54 55 return res 56 }