jsonenums/example/shirtsize.go

49 lines
633 B
Go

// 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 main
import (
"encoding/json"
"log"
"os"
)
//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
)
func main() {
v := struct {
Size ShirtSize
Day WeekDay
}{M, Friday}
if err := json.NewEncoder(os.Stdout).Encode(v); err != nil {
log.Fatal(err)
}
}