added demo file

This commit is contained in:
Francesc Campoy 2015-01-29 17:00:50 +01:00
parent 66a9dd356f
commit 10933b856e
3 changed files with 21 additions and 5 deletions

View File

@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package testdata
package main
import (
"encoding/json"
"log"
"os"
)
//go:generate jsonenums -type=ShirtSize
type ShirtSize byte
@ -28,3 +34,13 @@ const (
Saturday
Sunday
)
func main() {
v := struct {
Size ShirtSize
Day WeekDay
}{M, Friday}
if err := json.NewEncoder(os.Stdout).Encode(v); err != nil {
log.Fatal(err)
}
}

View File

@ -1,6 +1,6 @@
// generated by jsonenums -type=ShirtSize; DO NOT EDIT
package testdata
package main
import (
"encoding/json"
@ -63,7 +63,7 @@ func (r *ShirtSize) UnmarshalJSON(data []byte) error {
*r = XL
default:
return nil, fmt.Errorf("invalid ShirtSize %q", s)
return fmt.Errorf("invalid ShirtSize %q", s)
}
return nil
}

View File

@ -1,6 +1,6 @@
// generated by jsonenums -type=WeekDay; DO NOT EDIT
package testdata
package main
import (
"encoding/json"
@ -69,7 +69,7 @@ func (r *WeekDay) UnmarshalJSON(data []byte) error {
*r = Sunday
default:
return nil, fmt.Errorf("invalid WeekDay %q", s)
return fmt.Errorf("invalid WeekDay %q", s)
}
return nil
}