-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
50 lines (46 loc) · 984 Bytes
/
factory.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
package st2
import "github.com/tenfyzhong/st2/tmpl"
// CreateParser Create a [Parse] belongs to the context
func CreateParser(ctx Context) Parse {
switch ctx.Src {
case LangGo:
return NewGoParser(ctx)
case LangJson:
return NewJsonParser(ctx)
case LangYaml:
return NewYamlParser(ctx)
case LangProto:
return NewProtoParser(ctx)
case LangThrift:
return NewThriftParser(ctx)
case LangCsv:
return NewCsvParser(ctx)
case LangXML:
return NewXMLParser(ctx)
case LangToml:
return NewTomlParser(ctx)
}
return nil
}
// CreateTmpl Get the template data belongs to the context
func CreateTmpl(ctx Context) string {
switch ctx.Dst {
case LangGo:
return tmpl.Go
case LangJson:
case LangYaml:
case LangProto:
return tmpl.Proto
case LangThrift:
return tmpl.Thrift
}
return ""
}
// CreateFormater Create a [Format] to format code
func CreateFormater(ctx Context) Format {
switch ctx.Dst {
case LangGo:
return &GoFormater{}
}
return &EmptyFormater{}
}