Initial version
This commit is contained in:
33
compose/parser.go
Normal file
33
compose/parser.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package compose
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Parser struct {
|
||||
Data *Compose
|
||||
}
|
||||
|
||||
var Appname = ""
|
||||
|
||||
func NewParser(filename string) *Parser {
|
||||
|
||||
f, err := os.Open(filename)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
c := NewCompose()
|
||||
dec := yaml.NewDecoder(f)
|
||||
dec.Decode(c)
|
||||
|
||||
p := &Parser{Data: c}
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Parser) Parse(appname string) {
|
||||
Appname = appname
|
||||
}
|
24
compose/types.go
Normal file
24
compose/types.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package compose
|
||||
|
||||
type Service struct {
|
||||
Image string `yaml:"image"`
|
||||
Ports []string `yaml:"ports"`
|
||||
Environment map[string]string `yaml:"environment"`
|
||||
Labels map[string]string `yaml:"labels"`
|
||||
DependsOn []string `yaml:"depends_on"`
|
||||
Volumes []string `yaml:"volumes"`
|
||||
Expose []int `yaml:"expose"`
|
||||
}
|
||||
|
||||
type Compose struct {
|
||||
Version string `yaml:"version"`
|
||||
Services map[string]Service `yaml:"services"`
|
||||
Volumes map[string]interface{} `yaml:"volumes"`
|
||||
}
|
||||
|
||||
func NewCompose() *Compose {
|
||||
c := &Compose{}
|
||||
c.Services = make(map[string]Service)
|
||||
c.Volumes = make(map[string]interface{})
|
||||
return c
|
||||
}
|
Reference in New Issue
Block a user