Skip to content

Commit

Permalink
helper to set ports in the config
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldwan committed Feb 13, 2020
1 parent 86a7198 commit c1c6292
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions flyctl/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,29 @@ func (ac *AppConfig) WriteToFile(filename string) error {
return ac.WriteTo(file, ConfigFormatFromPath(filename))
}

func (ac *AppConfig) SetPorts(internal int, external int) bool {
if services, ok := ac.Definition["services"].([]interface{}); ok {
if len(services) == 0 {
return false
}

if service, ok := services[0].(map[string]interface{}); ok {
if ports, ok := service["ports"].([]interface{}); ok {
if len(ports) == 0 {
return false
}
if port, ok := ports[0].(map[string]interface{}); ok {
service["internal_port"] = internal
port["port"] = external
return true
}
}
}
}

return false
}

const defaultConfigFileName = "fly.toml"

func ResolveConfigFileFromPath(p string) (string, error) {
Expand Down

0 comments on commit c1c6292

Please sign in to comment.