|
| 1 | +// Generated by [optioner] command-line tool; DO NOT EDIT |
| 2 | +// If you have any questions, please create issues and submit contributions at: |
| 3 | +// https://github.com/chenmingyong0423/go-optioner |
| 4 | + |
| 5 | +// Copyright 2024 chenmingyong0423 |
| 6 | + |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | + |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | + |
| 19 | +package example |
| 20 | + |
| 21 | +import ( |
| 22 | + "context" |
| 23 | + |
| 24 | + "github.com/chenmingyong0423/go-optioner/example/third_party" |
| 25 | +) |
| 26 | + |
| 27 | +type _ struct { |
| 28 | + _ context.Context |
| 29 | +} |
| 30 | + |
| 31 | +type UserOption func(*User) |
| 32 | + |
| 33 | +func NewUser(embedded Embedded, embedded2 *Embedded2, e3 Embedded3, e4 *Embedded4, opts ...UserOption) *User { |
| 34 | + user := &User{ |
| 35 | + Embedded: embedded, |
| 36 | + Embedded2: embedded2, |
| 37 | + E3: e3, |
| 38 | + E4: e4, |
| 39 | + } |
| 40 | + |
| 41 | + for _, opt := range opts { |
| 42 | + opt(user) |
| 43 | + } |
| 44 | + |
| 45 | + return user |
| 46 | +} |
| 47 | + |
| 48 | +func WithEmbedded5(embedded5 Embedded5) UserOption { |
| 49 | + return func(user *User) { |
| 50 | + user.Embedded5 = embedded5 |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func WithEmbedded6(embedded6 *Embedded6) UserOption { |
| 55 | + return func(user *User) { |
| 56 | + user.Embedded6 = embedded6 |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +func WithE7(e7 Embedded7) UserOption { |
| 61 | + return func(user *User) { |
| 62 | + user.E7 = e7 |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func WithE8(e8 *Embedded8) UserOption { |
| 67 | + return func(user *User) { |
| 68 | + user.E8 = e8 |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +func WithUsername(username string) UserOption { |
| 73 | + return func(user *User) { |
| 74 | + user.Username = username |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func WithEmail(email string) UserOption { |
| 79 | + return func(user *User) { |
| 80 | + user.Email = email |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +func WithAddress(address Address) UserOption { |
| 85 | + return func(user *User) { |
| 86 | + user.Address = address |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +func WithArrayField(arrayField [4]int) UserOption { |
| 91 | + return func(user *User) { |
| 92 | + user.ArrayField = arrayField |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +func WithSliceField(sliceField []int) UserOption { |
| 97 | + return func(user *User) { |
| 98 | + user.SliceField = sliceField |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +func WithThirdPartyField(thirdPartyField third_party.ThirdParty) UserOption { |
| 103 | + return func(user *User) { |
| 104 | + user.ThirdPartyField = thirdPartyField |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +func WithMapField(mapField map[string]int) UserOption { |
| 109 | + return func(user *User) { |
| 110 | + user.MapField = mapField |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +func WithPtrField(ptrField *int) UserOption { |
| 115 | + return func(user *User) { |
| 116 | + user.PtrField = ptrField |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +func WithEmptyStructFiled(emptyStructFiled struct{}) UserOption { |
| 121 | + return func(user *User) { |
| 122 | + user.EmptyStructFiled = emptyStructFiled |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +func WithSimpleFuncField(simpleFuncField func()) UserOption { |
| 127 | + return func(user *User) { |
| 128 | + user.SimpleFuncField = simpleFuncField |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +func WithComplexFuncField(complexFuncField func(a int)) UserOption { |
| 133 | + return func(user *User) { |
| 134 | + user.ComplexFuncField = complexFuncField |
| 135 | + } |
| 136 | +} |
| 137 | + |
| 138 | +func WithComplexFuncFieldV2(complexFuncFieldV2 func() int) UserOption { |
| 139 | + return func(user *User) { |
| 140 | + user.ComplexFuncFieldV2 = complexFuncFieldV2 |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +func WithComplexFuncFieldV3(complexFuncFieldV3 func(a int) int) UserOption { |
| 145 | + return func(user *User) { |
| 146 | + user.ComplexFuncFieldV3 = complexFuncFieldV3 |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +func WithComplexFuncFieldV4(complexFuncFieldV4 func(a int) (int, error)) UserOption { |
| 151 | + return func(user *User) { |
| 152 | + user.ComplexFuncFieldV4 = complexFuncFieldV4 |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +func WithChanField(chanField chan int) UserOption { |
| 157 | + return func(user *User) { |
| 158 | + user.ChanField = chanField |
| 159 | + } |
| 160 | +} |
| 161 | + |
| 162 | +func WithError(error error) UserOption { |
| 163 | + return func(user *User) { |
| 164 | + user.error = error |
| 165 | + } |
| 166 | +} |
0 commit comments