本文整理匯總了Golang中github.com/flynn/flynn/bootstrap.Config類的典型用法代碼示例。如果您正苦於以下問題:Golang Config類的具體用法?Golang Config怎麽用?Golang Config使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Config類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: runBootstrap
func runBootstrap(args *docopt.Args) error {
log.SetFlags(log.Lmicroseconds)
logf := textLogger
if args.Bool["--json"] {
logf = jsonLogger
}
var cfg bootstrap.Config
manifestFile := args.String["<manifest>"]
if manifestFile == "" {
manifestFile = "/etc/flynn/bootstrap-manifest.json"
}
var steps []string
if s := args.String["--steps"]; s != "" {
steps = strings.Split(s, ",")
}
var err error
manifest, err = readBootstrapManifest(manifestFile)
if err != nil {
return fmt.Errorf("Error reading manifest: %s", err)
}
if n := args.String["--min-hosts"]; n != "" {
if cfg.MinHosts, err = strconv.Atoi(n); err != nil || cfg.MinHosts < 1 {
return fmt.Errorf("invalid --min-hosts value")
}
}
cfg.Timeout, err = strconv.Atoi(args.String["--timeout"])
if err != nil {
return fmt.Errorf("invalid --timeout value")
}
if ipList := args.String["--peer-ips"]; ipList != "" {
cfg.IPs = strings.Split(ipList, ",")
if cfg.MinHosts == 0 {
cfg.MinHosts = len(cfg.IPs)
}
}
if cfg.MinHosts == 0 {
cfg.MinHosts = 1
}
cfg.Singleton = cfg.MinHosts == 1
if s := os.Getenv("SINGLETON"); s != "" {
cfg.Singleton = s == "true"
}
ch := make(chan *bootstrap.StepInfo)
done := make(chan struct{})
var last error
go func() {
for si := range ch {
logf(si)
last = si.Err
}
close(done)
}()
cfg.ClusterURL = args.String["--discovery"]
if bf := args.String["--from-backup"]; bf != "" {
err = runBootstrapBackup(manifest, bf, ch, cfg)
} else {
err = bootstrap.Run(manifest, ch, cfg, steps)
}
<-done
if err != nil && last != nil && err.Error() == last.Error() {
return ErrAlreadyLogged{err}
}
return err
}
示例2: runBootstrapBackup
func runBootstrapBackup(manifest []byte, backupFile string, ch chan *bootstrap.StepInfo, cfg bootstrap.Config) error {
defer close(ch)
f, err := os.Open(backupFile)
if err != nil {
return fmt.Errorf("error opening backup file: %s", err)
}
defer f.Close()
tr := tar.NewReader(f)
getFile := func(name string) (io.Reader, error) {
rewound := false
var res io.Reader
for {
header, err := tr.Next()
if err == io.EOF && !rewound {
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return nil, fmt.Errorf("error seeking in backup file: %s", err)
}
rewound = true
tr = tar.NewReader(f)
continue
} else if err != nil {
return nil, fmt.Errorf("error finding %s in backup file: %s", name, err)
}
if path.Base(header.Name) != name {
continue
}
if strings.HasSuffix(name, ".gz") {
res, err = gzip.NewReader(tr)
if err != nil {
return nil, fmt.Errorf("error opening %s from backup file: %s", name, err)
}
} else {
res = tr
}
break
}
return res, nil
}
var data struct {
Discoverd, Flannel, Postgres, MariaDB, MongoDB, Controller *ct.ExpandedFormation
}
jsonData, err := getFile("flynn.json")
if err != nil {
return err
}
if jsonData == nil {
return fmt.Errorf("did not file flynn.json in backup file")
}
if err := json.NewDecoder(jsonData).Decode(&data); err != nil {
return fmt.Errorf("error decoding backup data: %s", err)
}
db, err := getFile("postgres.sql.gz")
if err != nil {
return err
}
if db == nil {
return fmt.Errorf("did not find postgres.sql.gz in backup file")
}
// add buffer to the end of the SQL import containing commands that rewrite data in the controller db
sqlBuf := &bytes.Buffer{}
db = io.MultiReader(db, sqlBuf)
sqlBuf.WriteString(fmt.Sprintf("\\connect %s\n", data.Controller.Release.Env["PGDATABASE"]))
sqlBuf.WriteString(`
CREATE FUNCTION pg_temp.json_object_update_key(
"json" jsonb,
"key_to_set" TEXT,
"value_to_set" TEXT
)
RETURNS jsonb
LANGUAGE sql
IMMUTABLE
STRICT
AS $function$
SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')::jsonb
FROM (SELECT *
FROM json_each("json"::json)
WHERE "key" <> "key_to_set"
UNION ALL
SELECT "key_to_set", to_json("value_to_set")) AS "fields"
$function$;
`)
type manifestStep struct {
ID string
Artifact struct {
URI string
}
Release struct {
Env map[string]string
Processes map[string]ct.ProcessType
}
}
var manifestSteps []*manifestStep
if err := json.Unmarshal(manifest, &manifestSteps); err != nil {
return fmt.Errorf("error decoding manifest json: %s", err)
//.........這裏部分代碼省略.........
示例3: runBootstrapBackup
func runBootstrapBackup(manifest []byte, backupFile string, ch chan *bootstrap.StepInfo, cfg bootstrap.Config) error {
defer close(ch)
f, err := os.Open(backupFile)
if err != nil {
return fmt.Errorf("error opening backup file: %s", err)
}
defer f.Close()
tr := tar.NewReader(f)
var data struct {
Discoverd, Flannel, Postgres, Controller *ct.ExpandedFormation
}
for {
header, err := tr.Next()
if err != nil {
return fmt.Errorf("error reading backup file: %s", err)
}
if path.Base(header.Name) != "flynn.json" {
continue
}
if err := json.NewDecoder(tr).Decode(&data); err != nil {
return fmt.Errorf("error decoding backup data: %s", err)
}
break
}
var db io.Reader
rewound := false
for {
header, err := tr.Next()
if err == io.EOF && !rewound {
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return fmt.Errorf("error seeking in backup file: %s", err)
}
rewound = true
} else if err != nil {
return fmt.Errorf("error finding db in backup file: %s", err)
}
if path.Base(header.Name) != "postgres.sql.gz" {
continue
}
db, err = gzip.NewReader(tr)
if err != nil {
return fmt.Errorf("error opening db from backup file: %s", err)
}
break
}
if db == nil {
return fmt.Errorf("did not found postgres.sql.gz in backup file")
}
// add buffer to the end of the SQL import containing commands that rewrite data in the controller db
sqlBuf := &bytes.Buffer{}
db = io.MultiReader(db, sqlBuf)
sqlBuf.WriteString(fmt.Sprintf("\\connect %s\n", data.Controller.Release.Env["PGDATABASE"]))
sqlBuf.WriteString(`
CREATE FUNCTION pg_temp.json_object_update_key(
"json" jsonb,
"key_to_set" TEXT,
"value_to_set" TEXT
)
RETURNS jsonb
LANGUAGE sql
IMMUTABLE
STRICT
AS $function$
SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')::jsonb
FROM (SELECT *
FROM json_each("json"::json)
WHERE "key" <> "key_to_set"
UNION ALL
SELECT "key_to_set", to_json("value_to_set")) AS "fields"
$function$;
`)
var manifestSteps []struct {
ID string
Artifact struct {
URI string
}
Release struct {
Env map[string]string
}
}
if err := json.Unmarshal(manifest, &manifestSteps); err != nil {
return fmt.Errorf("error decoding manifest json: %s", err)
}
artifactURIs := make(map[string]string)
for _, step := range manifestSteps {
if step.Artifact.URI != "" {
artifactURIs[step.ID] = step.Artifact.URI
if step.ID == "gitreceive" {
artifactURIs["slugbuilder"] = step.Release.Env["SLUGBUILDER_IMAGE_URI"]
artifactURIs["slugrunner"] = step.Release.Env["SLUGRUNNER_IMAGE_URI"]
}
// update current artifact in database for service
sqlBuf.WriteString(fmt.Sprintf(`
UPDATE artifacts SET uri = '%s'
WHERE artifact_id = (SELECT artifact_id FROM releases
WHERE release_id = (SELECT release_id FROM apps
WHERE name = '%s'));`, step.Artifact.URI, step.ID))
//.........這裏部分代碼省略.........
示例4: runBootstrapBackup
func runBootstrapBackup(manifest []byte, backupFile string, ch chan *bootstrap.StepInfo, cfg bootstrap.Config) error {
defer close(ch)
f, err := os.Open(backupFile)
if err != nil {
return fmt.Errorf("error opening backup file: %s", err)
}
defer f.Close()
tr := tar.NewReader(f)
getFile := func(name string) (io.Reader, error) {
rewound := false
var res io.Reader
for {
header, err := tr.Next()
if err == io.EOF && !rewound {
if _, err := f.Seek(0, os.SEEK_SET); err != nil {
return nil, fmt.Errorf("error seeking in backup file: %s", err)
}
rewound = true
tr = tar.NewReader(f)
continue
} else if err != nil {
return nil, fmt.Errorf("error finding %s in backup file: %s", name, err)
}
if path.Base(header.Name) != name {
continue
}
if strings.HasSuffix(name, ".gz") {
res, err = gzip.NewReader(tr)
if err != nil {
return nil, fmt.Errorf("error opening %s from backup file: %s", name, err)
}
} else {
res = tr
}
break
}
return res, nil
}
var data struct {
Discoverd, Flannel, Postgres, MariaDB, Controller *ct.ExpandedFormation
}
jsonData, err := getFile("flynn.json")
if err != nil {
return err
}
if jsonData == nil {
return fmt.Errorf("did not file flynn.json in backup file")
}
if err := json.NewDecoder(jsonData).Decode(&data); err != nil {
return fmt.Errorf("error decoding backup data: %s", err)
}
db, err := getFile("postgres.sql.gz")
if err != nil {
return err
}
if db == nil {
return fmt.Errorf("did not find postgres.sql.gz in backup file")
}
// add buffer to the end of the SQL import containing commands that rewrite data in the controller db
sqlBuf := &bytes.Buffer{}
db = io.MultiReader(db, sqlBuf)
sqlBuf.WriteString(fmt.Sprintf("\\connect %s\n", data.Controller.Release.Env["PGDATABASE"]))
sqlBuf.WriteString(`
CREATE FUNCTION pg_temp.json_object_update_key(
"json" jsonb,
"key_to_set" TEXT,
"value_to_set" TEXT
)
RETURNS jsonb
LANGUAGE sql
IMMUTABLE
STRICT
AS $function$
SELECT ('{' || string_agg(to_json("key") || ':' || "value", ',') || '}')::jsonb
FROM (SELECT *
FROM json_each("json"::json)
WHERE "key" <> "key_to_set"
UNION ALL
SELECT "key_to_set", to_json("value_to_set")) AS "fields"
$function$;
`)
var manifestSteps []struct {
ID string
Artifact struct {
URI string
}
Release struct {
Env map[string]string
}
}
if err := json.Unmarshal(manifest, &manifestSteps); err != nil {
return fmt.Errorf("error decoding manifest json: %s", err)
}
artifactURIs := make(map[string]string)
//.........這裏部分代碼省略.........