-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
945b81c
commit 96bb9b0
Showing
5 changed files
with
94 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,55 @@ | ||
package model | ||
|
||
import ( | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
const ( | ||
PbufConfigFilename = "pbuf.yaml" | ||
) | ||
|
||
type Config struct { | ||
Version string `yaml:"version"` | ||
Name string `yaml:"name"` | ||
Version string `yaml:"version,omitempty"` | ||
Name string `yaml:"name,omitempty"` | ||
Registry struct { | ||
Addr string `yaml:"addr"` | ||
Insecure bool `yaml:"insecure"` | ||
} `yaml:"registry"` | ||
Addr string `yaml:"addr,omitempty"` | ||
Insecure bool `yaml:"insecure,omitempty"` | ||
} `yaml:"registry,omitempty"` | ||
Export struct { | ||
Paths []string `yaml:"paths"` | ||
} `yaml:"export"` | ||
Modules []*Module `yaml:"modules"` | ||
Paths []string `yaml:"paths,omitempty"` | ||
} `yaml:"export,omitempty"` | ||
Modules []*Module `yaml:"modules,omitempty"` | ||
} | ||
|
||
type Module struct { | ||
Name string `yaml:"name"` | ||
Repository string `yaml:"repository"` | ||
Path string `yaml:"path"` | ||
Branch string `yaml:"branch"` | ||
Tag string `yaml:"tag"` | ||
OutputFolder string `yaml:"out"` | ||
GenerateOutputFolder string `yaml:"gen_out"` | ||
Name string `yaml:"name,omitempty"` | ||
Repository string `yaml:"repository,omitempty"` | ||
Path string `yaml:"path,omitempty"` | ||
Branch string `yaml:"branch,omitempty"` | ||
Tag string `yaml:"tag,omitempty"` | ||
OutputFolder string `yaml:"out,omitempty"` | ||
GenerateOutputFolder string `yaml:"gen_out,omitempty"` | ||
} | ||
|
||
func (c *Config) HasRegistry() bool { | ||
return c.Registry.Addr != "" | ||
} | ||
|
||
func (c *Config) Save() error { | ||
// encode to yaml and save to file PbufConfigFilename | ||
pbufYamlFile, err := os.OpenFile(PbufConfigFilename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
encoder := yaml.NewEncoder(pbufYamlFile) | ||
encoder.SetIndent(2) | ||
err = encoder.Encode(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters