Storage has now it's own package.
Remove global `sessions` map and use configured storage. Add a `types` package so both `pwd` and `storage` can access without circular dependencies. Now the session is prepared when requested and not on load.
This commit is contained in:
@@ -3,27 +3,29 @@ package pwd
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/play-with-docker/play-with-docker/pwd/types"
|
||||
)
|
||||
|
||||
type checkSwarmUsedPortsTask struct {
|
||||
}
|
||||
|
||||
func (c checkSwarmUsedPortsTask) Run(i *Instance) error {
|
||||
if i.docker == nil {
|
||||
func (c checkSwarmUsedPortsTask) Run(i *types.Instance) error {
|
||||
if i.Docker == nil {
|
||||
return nil
|
||||
}
|
||||
if i.IsManager != nil && *i.IsManager {
|
||||
sessionPrefix := i.session.Id[:8]
|
||||
sessionPrefix := i.Session.Id[:8]
|
||||
// This is a swarm manager instance, then check for ports
|
||||
if hosts, ports, err := i.docker.GetSwarmPorts(); err != nil {
|
||||
if hosts, ports, err := i.Docker.GetSwarmPorts(); err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
} else {
|
||||
for _, host := range hosts {
|
||||
host = fmt.Sprintf("%s_%s", sessionPrefix, host)
|
||||
for _, port := range ports {
|
||||
if i.session.Instances[host] != nil {
|
||||
i.session.Instances[host].setUsedPort(port)
|
||||
if i.Session.Instances[host] != nil {
|
||||
i.Session.Instances[host].SetUsedPort(port)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user