Browse Source

Clean up unused files

master
Nise Void 8 months ago
parent
commit
8f2162190b
Signed by: NiseVoid <nisevoid@gmail.com> GPG Key ID: FBA14AC83EA602F3
9 changed files with 0 additions and 523 deletions
  1. 0
    24
      .gitignore
  2. 0
    9
      .travis.yml
  3. 0
    86
      example/shirtsize.go
  4. 0
    68
      example/shirtsize_jsonenums.go
  5. 0
    71
      example/weekday_jsonenums.go
  6. 0
    21
      server/app.yaml
  7. 0
    32
      server/main.go
  8. 0
    124
      server/server.go
  9. 0
    88
      server/static/home.html

+ 0
- 24
.gitignore View File

@@ -1,24 +0,0 @@
1
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
2
-*.o
3
-*.a
4
-*.so
5
-
6
-# Folders
7
-_obj
8
-_test
9
-
10
-# Architecture specific extensions/prefixes
11
-*.[568vq]
12
-[568vq].out
13
-
14
-*.cgo1.go
15
-*.cgo2.c
16
-_cgo_defun.c
17
-_cgo_gotypes.go
18
-_cgo_export.*
19
-
20
-_testmain.go
21
-
22
-*.exe
23
-*.test
24
-*.prof

+ 0
- 9
.travis.yml View File

@@ -1,9 +0,0 @@
1
-language: go
2
-
3
-go:
4
-  - 1.7
5
-  - 1.8
6
-  - master
7
-script:
8
-  # The GOPATH is for testing #21
9
-  - GOPATH="$GOPATH:/tmp/jsonenums-test/go1:/tmp/jsonenums-test/go2" go test ./... 

+ 0
- 86
example/shirtsize.go View File

@@ -1,86 +0,0 @@
1
-// Copyright 2017 Google Inc. All rights reserved.
2
-// Licensed under the Apache License, Version 2.0 (the "License");
3
-// you may not use this file except in compliance with the License.
4
-// You may obtain a copy of the License at
5
-// http://www.apache.org/licenses/LICENSE-2.0
6
-//
7
-// Unless required by applicable law or agreed to writing, software distributed
8
-// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9
-// CONDITIONS OF ANY KIND, either express or implied.
10
-//
11
-// See the License for the specific language governing permissions and
12
-// limitations under the License.
13
-
14
-package main
15
-
16
-import (
17
-	"encoding/json"
18
-	"fmt"
19
-	"log"
20
-	"os"
21
-	"strings"
22
-)
23
-
24
-//go:generate jsonenums -type=ShirtSize
25
-
26
-type ShirtSize byte
27
-
28
-const (
29
-	NA ShirtSize = iota
30
-	XS
31
-	S
32
-	M
33
-	L
34
-	XL
35
-)
36
-
37
-//go:generate jsonenums -type=WeekDay
38
-
39
-type WeekDay int
40
-
41
-const (
42
-	Monday WeekDay = iota
43
-	Tuesday
44
-	Wednesday
45
-	Thursday
46
-	Friday
47
-	Saturday
48
-	Sunday
49
-)
50
-
51
-func (d WeekDay) String() string {
52
-	switch d {
53
-	case Monday:
54
-		return "Dilluns"
55
-	case Tuesday:
56
-		return "Dimarts"
57
-	case Wednesday:
58
-		return "Dimecres"
59
-	case Thursday:
60
-		return "Dijous"
61
-	case Friday:
62
-		return "Divendres"
63
-	case Saturday:
64
-		return "Dissabte"
65
-	case Sunday:
66
-		return "Diumenge"
67
-	default:
68
-		return "invalid WeekDay"
69
-	}
70
-}
71
-
72
-func main() {
73
-	v := struct {
74
-		Size ShirtSize
75
-		Day  WeekDay
76
-	}{M, Friday}
77
-	if err := json.NewEncoder(os.Stdout).Encode(v); err != nil {
78
-		log.Fatal(err)
79
-	}
80
-
81
-	input := `{"Size":"XL", "Day":"Dimarts"}`
82
-	if err := json.NewDecoder(strings.NewReader(input)).Decode(&v); err != nil {
83
-		log.Fatal(err)
84
-	}
85
-	fmt.Printf("decoded %s as %+v\n", input, v)
86
-}

+ 0
- 68
example/shirtsize_jsonenums.go View File

@@ -1,68 +0,0 @@
1
-// generated by jsonenums -type=ShirtSize; DO NOT EDIT
2
-
3
-package main
4
-
5
-import (
6
-	"encoding/json"
7
-	"fmt"
8
-)
9
-
10
-var (
11
-	_ShirtSizeNameToValue = map[string]ShirtSize{
12
-		"NA": NA,
13
-		"XS": XS,
14
-		"S":  S,
15
-		"M":  M,
16
-		"L":  L,
17
-		"XL": XL,
18
-	}
19
-
20
-	_ShirtSizeValueToName = map[ShirtSize]string{
21
-		NA: "NA",
22
-		XS: "XS",
23
-		S:  "S",
24
-		M:  "M",
25
-		L:  "L",
26
-		XL: "XL",
27
-	}
28
-)
29
-
30
-func init() {
31
-	var v ShirtSize
32
-	if _, ok := interface{}(v).(fmt.Stringer); ok {
33
-		_ShirtSizeNameToValue = map[string]ShirtSize{
34
-			interface{}(NA).(fmt.Stringer).String(): NA,
35
-			interface{}(XS).(fmt.Stringer).String(): XS,
36
-			interface{}(S).(fmt.Stringer).String():  S,
37
-			interface{}(M).(fmt.Stringer).String():  M,
38
-			interface{}(L).(fmt.Stringer).String():  L,
39
-			interface{}(XL).(fmt.Stringer).String(): XL,
40
-		}
41
-	}
42
-}
43
-
44
-// MarshalJSON is generated so ShirtSize satisfies json.Marshaler.
45
-func (r ShirtSize) MarshalJSON() ([]byte, error) {
46
-	if s, ok := interface{}(r).(fmt.Stringer); ok {
47
-		return json.Marshal(s.String())
48
-	}
49
-	s, ok := _ShirtSizeValueToName[r]
50
-	if !ok {
51
-		return nil, fmt.Errorf("invalid ShirtSize: %d", r)
52
-	}
53
-	return json.Marshal(s)
54
-}
55
-
56
-// UnmarshalJSON is generated so ShirtSize satisfies json.Unmarshaler.
57
-func (r *ShirtSize) UnmarshalJSON(data []byte) error {
58
-	var s string
59
-	if err := json.Unmarshal(data, &s); err != nil {
60
-		return fmt.Errorf("ShirtSize should be a string, got %s", data)
61
-	}
62
-	v, ok := _ShirtSizeNameToValue[s]
63
-	if !ok {
64
-		return fmt.Errorf("invalid ShirtSize %q", s)
65
-	}
66
-	*r = v
67
-	return nil
68
-}

+ 0
- 71
example/weekday_jsonenums.go View File

@@ -1,71 +0,0 @@
1
-// generated by jsonenums -type=WeekDay; DO NOT EDIT
2
-
3
-package main
4
-
5
-import (
6
-	"encoding/json"
7
-	"fmt"
8
-)
9
-
10
-var (
11
-	_WeekDayNameToValue = map[string]WeekDay{
12
-		"Monday":    Monday,
13
-		"Tuesday":   Tuesday,
14
-		"Wednesday": Wednesday,
15
-		"Thursday":  Thursday,
16
-		"Friday":    Friday,
17
-		"Saturday":  Saturday,
18
-		"Sunday":    Sunday,
19
-	}
20
-
21
-	_WeekDayValueToName = map[WeekDay]string{
22
-		Monday:    "Monday",
23
-		Tuesday:   "Tuesday",
24
-		Wednesday: "Wednesday",
25
-		Thursday:  "Thursday",
26
-		Friday:    "Friday",
27
-		Saturday:  "Saturday",
28
-		Sunday:    "Sunday",
29
-	}
30
-)
31
-
32
-func init() {
33
-	var v WeekDay
34
-	if _, ok := interface{}(v).(fmt.Stringer); ok {
35
-		_WeekDayNameToValue = map[string]WeekDay{
36
-			interface{}(Monday).(fmt.Stringer).String():    Monday,
37
-			interface{}(Tuesday).(fmt.Stringer).String():   Tuesday,
38
-			interface{}(Wednesday).(fmt.Stringer).String(): Wednesday,
39
-			interface{}(Thursday).(fmt.Stringer).String():  Thursday,
40
-			interface{}(Friday).(fmt.Stringer).String():    Friday,
41
-			interface{}(Saturday).(fmt.Stringer).String():  Saturday,
42
-			interface{}(Sunday).(fmt.Stringer).String():    Sunday,
43
-		}
44
-	}
45
-}
46
-
47
-// MarshalJSON is generated so WeekDay satisfies json.Marshaler.
48
-func (r WeekDay) MarshalJSON() ([]byte, error) {
49
-	if s, ok := interface{}(r).(fmt.Stringer); ok {
50
-		return json.Marshal(s.String())
51
-	}
52
-	s, ok := _WeekDayValueToName[r]
53
-	if !ok {
54
-		return nil, fmt.Errorf("invalid WeekDay: %d", r)
55
-	}
56
-	return json.Marshal(s)
57
-}
58
-
59
-// UnmarshalJSON is generated so WeekDay satisfies json.Unmarshaler.
60
-func (r *WeekDay) UnmarshalJSON(data []byte) error {
61
-	var s string
62
-	if err := json.Unmarshal(data, &s); err != nil {
63
-		return fmt.Errorf("WeekDay should be a string, got %s", data)
64
-	}
65
-	v, ok := _WeekDayNameToValue[s]
66
-	if !ok {
67
-		return fmt.Errorf("invalid WeekDay %q", s)
68
-	}
69
-	*r = v
70
-	return nil
71
-}

+ 0
- 21
server/app.yaml View File

@@ -1,21 +0,0 @@
1
-# Unless required by applicable law or agreed to writing, software distributed
2
-# under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
3
-# CONDITIONS OF ANY KIND, either express or implied.
4
-
5
-# See the License for the specific language governing permissions and
6
-# limitations under the License.
7
-
8
-version: gae
9
-runtime: go
10
-api_version: go1
11
-
12
-handlers:
13
-- url: /generate
14
-  script: _go_app
15
-
16
-- url: /
17
-  static_files: static/home.html
18
-  upload: static/home.html
19
-
20
-- url: /
21
-  static_dir: static

+ 0
- 32
server/main.go View File

@@ -1,32 +0,0 @@
1
-// Copyright 2017 Google Inc. All rights reserved.
2
-// Licensed under the Apache License, Version 2.0 (the "License");
3
-// you may not use this file except in compliance with the License.
4
-// You may obtain a copy of the License at
5
-// http://www.apache.org/licenses/LICENSE-2.0
6
-//
7
-// Unless required by applicable law or agreed to writing, software distributed
8
-// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9
-// CONDITIONS OF ANY KIND, either express or implied.
10
-//
11
-// See the License for the specific language governing permissions and
12
-// limitations under the License.
13
-
14
-// +build !appengine
15
-
16
-package main
17
-
18
-import (
19
-	"flag"
20
-	"net/http"
21
-)
22
-
23
-func main() {
24
-	port := flag.String("http", "127.0.0.1:8080", "ip and port to listen to")
25
-	flag.Parse()
26
-	http.HandleFunc("/", homeHandler)
27
-	http.ListenAndServe(*port, nil)
28
-}
29
-
30
-func homeHandler(w http.ResponseWriter, r *http.Request) {
31
-	http.ServeFile(w, r, "static/home.html")
32
-}

+ 0
- 124
server/server.go View File

@@ -1,124 +0,0 @@
1
-// Copyright 2017 Google Inc. All rights reserved.
2
-// Licensed under the Apache License, Version 2.0 (the "License");
3
-// you may not use this file except in compliance with the License.
4
-// You may obtain a copy of the License at
5
-// http://www.apache.org/licenses/LICENSE-2.0
6
-//
7
-// Unless required by applicable law or agreed to writing, software distributed
8
-// under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
9
-// CONDITIONS OF ANY KIND, either express or implied.
10
-//
11
-// See the License for the specific language governing permissions and
12
-// limitations under the License.
13
-
14
-// Server is an http server that provides an alternative way of generating code
15
-// based on int types and the constants defined with it.
16
-//
17
-// Use the http flag to change the address on which the server will listen for
18
-// requests. The default is 127.0.0.1:8080.
19
-package main
20
-
21
-import (
22
-	"bytes"
23
-	"fmt"
24
-	"io/ioutil"
25
-	"log"
26
-	"net/http"
27
-	"os"
28
-	"path/filepath"
29
-	"text/template"
30
-
31
-	"go/format"
32
-
33
-	"github.com/campoy/jsonenums/parser"
34
-)
35
-
36
-func init() {
37
-	http.Handle("/generate", handler(generateHandler))
38
-}
39
-
40
-func generateHandler(w http.ResponseWriter, r *http.Request) error {
41
-	if r.Method != "GET" {
42
-		return codeError{fmt.Errorf("only GET accepted"), http.StatusMethodNotAllowed}
43
-	}
44
-	code := r.FormValue("code")
45
-	if code == "" {
46
-		return codeError{fmt.Errorf("no code to be parsed"), http.StatusBadRequest}
47
-	}
48
-	typ := r.FormValue("type")
49
-	if typ == "" {
50
-		return codeError{fmt.Errorf("no type to be analyzed"), http.StatusBadRequest}
51
-	}
52
-
53
-	dir, err := createDir(code)
54
-	if err != nil {
55
-		return err
56
-	}
57
-	defer os.RemoveAll(dir)
58
-
59
-	pkg, err := parser.ParsePackage(dir)
60
-	if err != nil {
61
-		return fmt.Errorf("parse package: %v", err)
62
-	}
63
-
64
-	values, err := pkg.ValuesOfType(typ)
65
-	if err != nil {
66
-		return fmt.Errorf("find values: %v", err)
67
-	}
68
-
69
-	t, err := template.New("code").Parse(r.FormValue("template"))
70
-	if err != nil {
71
-		return codeError{fmt.Errorf("parse template: %v", err), http.StatusBadRequest}
72
-	}
73
-	var data = struct {
74
-		PackageName string
75
-		TypeName    string
76
-		Values      []string
77
-	}{pkg.Name, typ, values}
78
-
79
-	var buf bytes.Buffer
80
-	if err := t.Execute(&buf, data); err != nil {
81
-		return codeError{fmt.Errorf("execute template: %v", err), http.StatusBadRequest}
82
-	}
83
-	src, err := format.Source(buf.Bytes())
84
-	if err != nil {
85
-		return codeError{fmt.Errorf("code generated is not valid: %v\n%v", err, buf.String()), http.StatusBadRequest}
86
-	}
87
-	w.Write(src)
88
-	return nil
89
-}
90
-
91
-func createDir(content string) (string, error) {
92
-	dir, err := ioutil.TempDir("", "jsonenums")
93
-	if err != nil {
94
-		return "", fmt.Errorf("create tmp dir: %v", err)
95
-	}
96
-	f, err := os.Create(filepath.Join(dir, "main.go"))
97
-	if err != nil {
98
-		os.RemoveAll(dir)
99
-		return "", fmt.Errorf("create tmp file: %v", err)
100
-	}
101
-	f.WriteString(content)
102
-	f.Close()
103
-	return dir, err
104
-}
105
-
106
-type handler func(http.ResponseWriter, *http.Request) error
107
-
108
-func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
109
-	err := h(w, r)
110
-	if err != nil {
111
-		code := http.StatusInternalServerError
112
-		if cErr, ok := err.(codeError); ok {
113
-			code = cErr.code
114
-		} else {
115
-			log.Printf("%v: %v", r.URL, code)
116
-		}
117
-		http.Error(w, err.Error(), code)
118
-	}
119
-}
120
-
121
-type codeError struct {
122
-	error
123
-	code int
124
-}

+ 0
- 88
server/static/home.html View File

@@ -1,88 +0,0 @@
1
-<!DOCTYPE html>
2
-
3
-<!--
4
-Copyright 2017 Google Inc. All rights reserved.
5
-Licensed under the Apache License, Version 2.0 (the "License");
6
-you may not use this file except in compliance with the License.
7
-You may obtain a copy of the License at
8
-http://www.apache.org/licenses/LICENSE-2.0
9
-Unless required by applicable law or agreed to writing, software distributed
10
-under the License is distributed on a "AS IS" BASIS, WITHOUT WARRANTIES OR
11
-CONDITIONS OF ANY KIND, either express or implied.
12
-See the License for the specific language governing permissions and
13
-limitations under the License.
14
--->
15
-
16
-<html>
17
-<title>jsonenums</title>
18
-<style>
19
-    textarea,
20
-    input {
21
-        display: block;
22
-        width: 80%;
23
-        margin: auto;
24
-    }
25
-    textarea {
26
-        height: 200px;
27
-        overflow-y: scroll;
28
-    }
29
-</style>
30
-
31
-<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
32
-<script>
33
-    function generate() {
34
-        $.get("/generate", {
35
-            "code": $("#code").val(),
36
-            "type": $("#type").val(),
37
-            "template": $("#template").val(),
38
-        }).done(function(res) {
39
-            $("#result").val(res);
40
-            $("#result").css('background','#fff');
41
-        }).fail(function(res) {
42
-            $("#result").val(res.responseText);
43
-            $("#result").css('background','#fee');
44
-        })
45
-    }
46
-</script>
47
-
48
-<body>
49
-
50
-    <form action="/generate" method="GET">
51
-        <input type="text" id="type" value="WeekDay">
52
-        <textarea id="code">
53
-package test
54
-
55
-type WeekDay int
56
-
57
-const (
58
-    Monday WeekDay = iota
59
-    Tuesday
60
-    Wednesday
61
-    Thursday
62
-    Friday
63
-    Saturday
64
-    Sunday
65
-)
66
-        </textarea>
67
-        <textarea id="template">
68
-package {{.PackageName}}
69
-
70
-func (r {{.TypeName}}) String() string {
71
-    s, ok := map[{{.TypeName}}]string {
72
-        {{range .Values}}{{.}}:"{{.}}",{{end}}
73
-    }
74
-    if !ok {
75
-        return "unknown {{.TypeName}}"
76
-    }
77
-    return s
78
-}
79
-        </textarea>
80
-    </form>
81
-
82
-    <input type="button" onclick="generate()" value="generate code">
83
-
84
-    <textarea id="result">
85
-    </textarea>
86
-</body>
87
-
88
-</html>

Loading…
Cancel
Save