-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
35 lines (24 loc) · 804 Bytes
/
main.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
package gelm
import (
"fmt"
)
// Generate Elm type aliases with decoder functions as a module.
func Generate(moduleName string, types ...interface{}) []byte {
output := []byte(fmt.Sprintf(`-- This file was generated with github.com/yitsushi/gelm
-- Do not edit this file unless you know what you are doing.
module %s exposing (..)
import Json.Decode as Decode
import Json.Decode.Pipeline as Dp`, moduleName))
for _, obj := range types {
typeDef := parse(obj)
output = append(output, []byte{'\n', '\n', '\n'}...)
output = append(output, generateTypeAlias(typeDef)...)
}
for _, obj := range types {
typeDef := parse(obj)
output = append(output, []byte{'\n', '\n', '\n'}...)
output = append(output, generateDecoder(typeDef)...)
}
output = append(output, '\n')
return output
}