forked from 33cn/chain33
/
strategy.go
77 lines (67 loc) · 1.62 KB
/
strategy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package strategy
import (
"fmt"
"github.com/33cn/chain33/cmd/tools/types"
"github.com/33cn/chain33/common/log/log15"
"github.com/pkg/errors"
)
var (
mlog = log15.New("module", "strategy")
)
type Strategy interface {
SetParam(key string, value string)
Run() error
}
func New(name string) Strategy {
switch name {
case types.KeyImportPackage:
return &importPackageStrategy{
strategyBasic: strategyBasic{
params: make(map[string]string),
},
}
case types.KeyCreateSimpleExecProject:
return &simpleCreateExecProjStrategy{
strategyBasic: strategyBasic{
params: make(map[string]string),
},
}
case types.KeyCreateAdvanceExecProject:
return &advanceCreateExecProjStrategy{
strategyBasic: strategyBasic{
params: make(map[string]string),
},
}
case types.KeyUpdateInit:
return &updateInitStrategy{
strategyBasic: strategyBasic{
params: make(map[string]string),
},
}
case types.KeyCreatePlugin:
return &createPluginStrategy{
strategyBasic: strategyBasic{
params: make(map[string]string),
},
}
}
return nil
}
type strategyBasic struct {
params map[string]string
}
func (this *strategyBasic) SetParam(key string, value string) {
this.params[key] = value
}
func (this *strategyBasic) getParam(key string) (string, error) {
if v, ok := this.params[key]; ok {
return v, nil
}
return "", errors.New(fmt.Sprintf("Key:%v not existed.", key))
}
func (this *strategyBasic) Run() error {
return errors.New("NotSupport")
}