From 10933b856e570af2c6482962d71e516dcad12828 Mon Sep 17 00:00:00 2001 From: Francesc Campoy Date: Thu, 29 Jan 2015 17:00:50 +0100 Subject: [PATCH] added demo file --- example/shirtsize.go | 18 +++++++++++++++++- example/shirtsize_jsonenums.go | 4 ++-- example/weekday_jsonenums.go | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/example/shirtsize.go b/example/shirtsize.go index 41ed848..4bdf15e 100644 --- a/example/shirtsize.go +++ b/example/shirtsize.go @@ -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) + } +} diff --git a/example/shirtsize_jsonenums.go b/example/shirtsize_jsonenums.go index 7fc4f47..a2432d6 100644 --- a/example/shirtsize_jsonenums.go +++ b/example/shirtsize_jsonenums.go @@ -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 } diff --git a/example/weekday_jsonenums.go b/example/weekday_jsonenums.go index 1ce2f9b..38b923f 100644 --- a/example/weekday_jsonenums.go +++ b/example/weekday_jsonenums.go @@ -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 }