initial commit

This commit is contained in:
Francesc Campoy 2015-01-29 11:35:15 +01:00
parent fb5644d041
commit 66a9dd356f
6 changed files with 587 additions and 1 deletions

30
example/shirtsize.go Normal file
View file

@ -0,0 +1,30 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testdata
//go:generate jsonenums -type=ShirtSize
type ShirtSize byte
const (
NA ShirtSize = iota
XS
S
M
L
XL
)
//go:generate jsonenums -type=WeekDay
type WeekDay int
const (
Monday WeekDay = iota
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
)

View file

@ -0,0 +1,69 @@
// generated by jsonenums -type=ShirtSize; DO NOT EDIT
package testdata
import (
"encoding/json"
"fmt"
)
func (r ShirtSize) String() string {
switch r {
case NA:
return "NA"
case XS:
return "XS"
case S:
return "S"
case M:
return "M"
case L:
return "L"
case XL:
return "XL"
default:
return "unknown ShirtSize"
}
}
func (r ShirtSize) MarshalJSON() ([]byte, error) {
return json.Marshal(r.String())
}
func (r *ShirtSize) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("ShirtSize should be a string, got %s", data)
}
switch s {
case "NA":
*r = NA
case "XS":
*r = XS
case "S":
*r = S
case "M":
*r = M
case "L":
*r = L
case "XL":
*r = XL
default:
return nil, fmt.Errorf("invalid ShirtSize %q", s)
}
return nil
}

View file

@ -0,0 +1,75 @@
// generated by jsonenums -type=WeekDay; DO NOT EDIT
package testdata
import (
"encoding/json"
"fmt"
)
func (r WeekDay) String() string {
switch r {
case Monday:
return "Monday"
case Tuesday:
return "Tuesday"
case Wednesday:
return "Wednesday"
case Thursday:
return "Thursday"
case Friday:
return "Friday"
case Saturday:
return "Saturday"
case Sunday:
return "Sunday"
default:
return "unknown WeekDay"
}
}
func (r WeekDay) MarshalJSON() ([]byte, error) {
return json.Marshal(r.String())
}
func (r *WeekDay) UnmarshalJSON(data []byte) error {
var s string
if err := json.Unmarshal(data, &s); err != nil {
return fmt.Errorf("WeekDay should be a string, got %s", data)
}
switch s {
case "Monday":
*r = Monday
case "Tuesday":
*r = Tuesday
case "Wednesday":
*r = Wednesday
case "Thursday":
*r = Thursday
case "Friday":
*r = Friday
case "Saturday":
*r = Saturday
case "Sunday":
*r = Sunday
default:
return nil, fmt.Errorf("invalid WeekDay %q", s)
}
return nil
}