1
0
Fork 0
mirror of https://github.com/Luzifer/update-gotools.git synced 2024-12-22 21:01:20 +00:00
update-gotools/types.go
Knut Ahlers fec20c1163
Allow fetching version from a remote URL
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-02-20 22:45:45 +01:00

45 lines
822 B
Go

package main
import (
"io/ioutil"
"net/http"
)
type pkgCfg struct {
Name string `yaml:"name"`
Single bool `yaml:"single"`
Ver string `yaml:"version"`
VersionURL string `yaml:"version_url"`
}
type configFile struct {
Cwd string `yaml:"cwd"`
GoPath string `yaml:"gopath"`
Packages []pkgCfg `yaml:"packages"`
PreCommands [][]string `yaml:"pre_commands"`
PostCommands [][]string `yaml:"post_commands"`
}
func (p *pkgCfg) Version() (string, error) {
if p.Ver != "" {
return p.Ver, nil
}
if p.VersionURL != "" {
resp, err := http.Get(p.VersionURL)
if err != nil {
return "", err
}
defer resp.Body.Close()
v, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
p.Ver = string(v)
return p.Ver, nil
}
return "", nil
}