/
map_gen.go
81 lines (68 loc) · 1.76 KB
/
map_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Code generated by github.com/alextanhongpin/builder, DO NOT EDIT.
package main
import (
"fmt"
uuid "github.com/google/uuid"
)
type CacheBuilder struct {
cache Cache
fields map[string]int
fieldsSet uint64
}
func NewCacheBuilder() *CacheBuilder {
fields := make(map[string]int)
for i, field := range []string{"userByID", "booksByAuthorID", "userByIDByName"} {
fields[field] = i
}
return &CacheBuilder{fields: fields}
}
// WithUserByID sets userByID.
func (b CacheBuilder) WithUserByID(userByID map[uuid.UUID]*User) CacheBuilder {
b.cache.userByID = userByID
b.Set("userByID")
return b
}
// WithBooksByAuthorID sets booksByAuthorID.
func (b CacheBuilder) WithBooksByAuthorID(booksByAuthorID map[int64][]Book) CacheBuilder {
b.cache.booksByAuthorID = booksByAuthorID
b.Set("booksByAuthorID")
return b
}
// WithUserByIDByName sets userByIDByName.
func (b CacheBuilder) WithUserByIDByName(userByIDByName map[string]map[int64]User) CacheBuilder {
b.cache.userByIDByName = userByIDByName
b.Set("userByIDByName")
return b
}
// Build returns Cache.
func (b CacheBuilder) Build() Cache {
for field := range b.fields {
if !b.IsSet(field) {
panic(fmt.Errorf("builder: %q not set", field))
}
}
return b.cache
}
// Build returns Cache.
func (b CacheBuilder) BuildPartial() Cache {
return b.cache
}
func (b *CacheBuilder) Set(field string) bool {
n, ok := b.fields[field]
if !ok {
return false
}
b.fieldsSet |= 1 << n
return true
}
func (b CacheBuilder) IsSet(field string) bool {
pos := b.fields[field]
return (b.fieldsSet & (1 << pos)) == (1 << pos)
}
func (b *CacheBuilder) Register(field string) error {
if _, ok := b.fields[field]; ok {
return fmt.Errorf("field %q already registered", field)
}
b.fields[field] = len(b.fields)
return nil
}