mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-05 09:53:21 +08:00
Initial commit
This commit is contained in:
39
services/instance.go
Normal file
39
services/instance.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package services
|
||||
|
||||
import "github.com/xetorthio/play-with-docker/types"
|
||||
|
||||
var instances map[string]map[string]*types.Instance
|
||||
|
||||
func init() {
|
||||
instances = make(map[string]map[string]*types.Instance)
|
||||
}
|
||||
|
||||
func NewInstance(session *types.Session) (*types.Instance, error) {
|
||||
//TODO: Validate that a session can only have 10 instances
|
||||
|
||||
//TODO: Create in redis
|
||||
|
||||
instance, err := CreateInstance(session.Id)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if instances[session.Id] == nil {
|
||||
instances[session.Id] = make(map[string]*types.Instance)
|
||||
}
|
||||
instances[session.Id][instance.Name] = instance
|
||||
|
||||
return instance, nil
|
||||
}
|
||||
|
||||
func GetInstance(session *types.Session, instanceId string) *types.Instance {
|
||||
//TODO: Use redis
|
||||
i := instances[session.Id][instanceId]
|
||||
return i
|
||||
}
|
||||
func DeleteInstance(session *types.Session, instance *types.Instance) error {
|
||||
//TODO: Use redis
|
||||
delete(instances[session.Id], instance.Name)
|
||||
return DeleteContainer(instance.Name)
|
||||
}
|
Reference in New Issue
Block a user