-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 生成代码时,加上 imports 信息 - 支持更多的结构体字段类型 - gkit 依赖升级至 v0.0.4
- Loading branch information
1 parent
d8e9541
commit 59164c0
Showing
8 changed files
with
290 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// Generated by optioner -type User; DO NOT EDIT | ||
// If you have any questions, please create issues and submit contributions at: | ||
// https://github.com/chenmingyong0423/go-optioner | ||
|
||
package example | ||
|
||
import ( | ||
"github.com/chenmingyong0423/go-optioner/example/third_party" | ||
) | ||
|
||
type UserOption func(*User) | ||
|
||
func NewUser(opts ...UserOption) *User { | ||
user := &User{} | ||
|
||
for _, opt := range opts { | ||
opt(user) | ||
} | ||
|
||
return user | ||
} | ||
|
||
func WithUsername(username string) UserOption { | ||
return func(user *User) { | ||
user.Username = username | ||
} | ||
} | ||
|
||
func WithEmail(email string) UserOption { | ||
return func(user *User) { | ||
user.Email = email | ||
} | ||
} | ||
|
||
func WithAddress(address Address) UserOption { | ||
return func(user *User) { | ||
user.Address = address | ||
} | ||
} | ||
|
||
func WithArrayField(arrayField [4]int) UserOption { | ||
return func(user *User) { | ||
user.ArrayField = arrayField | ||
} | ||
} | ||
|
||
func WithSliceField(sliceField []int) UserOption { | ||
return func(user *User) { | ||
user.SliceField = sliceField | ||
} | ||
} | ||
|
||
func WithThirdPartyField(thirdPartyField third_party.ThirdParty) UserOption { | ||
return func(user *User) { | ||
user.ThirdPartyField = thirdPartyField | ||
} | ||
} | ||
|
||
func WithMapField(mapField map[string]int) UserOption { | ||
return func(user *User) { | ||
user.MapField = mapField | ||
} | ||
} | ||
|
||
func WithPtrField(ptrField *int) UserOption { | ||
return func(user *User) { | ||
user.PtrField = ptrField | ||
} | ||
} | ||
|
||
func WithEmptyStructFiled(emptyStructFiled struct{}) UserOption { | ||
return func(user *User) { | ||
user.EmptyStructFiled = emptyStructFiled | ||
} | ||
} | ||
|
||
func WithSimpleFuncField(simpleFuncField func()) UserOption { | ||
return func(user *User) { | ||
user.SimpleFuncField = simpleFuncField | ||
} | ||
} | ||
|
||
func WithComplexFuncField(complexFuncField func(a int)) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncField = complexFuncField | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV2(complexFuncFieldV2 func() int) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV2 = complexFuncFieldV2 | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV3(complexFuncFieldV3 func(a int) int) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV3 = complexFuncFieldV3 | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV4(complexFuncFieldV4 func(a int) (int, error)) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV4 = complexFuncFieldV4 | ||
} | ||
} | ||
|
||
func WithChanField(chanField chan int) UserOption { | ||
return func(user *User) { | ||
user.ChanField = chanField | ||
} | ||
} | ||
|
||
func WithError(error error) UserOption { | ||
return func(user *User) { | ||
user.error = error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2023 chenmingyong0423 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package third_party | ||
|
||
type ThirdParty struct { | ||
Name string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 chenmingyong0423 | ||
|
||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
|
||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package example | ||
|
||
import ( | ||
"github.com/chenmingyong0423/go-optioner/example/third_party" | ||
) | ||
|
||
type User struct { | ||
Username string | ||
Email string | ||
Address // combined struct | ||
ArrayField [4]int | ||
SliceField []int | ||
ThirdPartyField third_party.ThirdParty | ||
MapField map[string]int | ||
PtrField *int | ||
EmptyStructFiled struct{} | ||
SimpleFuncField func() | ||
ComplexFuncField func(a int) | ||
ComplexFuncFieldV2 func() int | ||
ComplexFuncFieldV3 func(a int) int | ||
ComplexFuncFieldV4 func(a int) (int, error) | ||
ChanField chan int | ||
error // interface | ||
} | ||
|
||
type Address struct { | ||
Street string | ||
City string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/chenmingyong0423/go-optioner | ||
|
||
go 1.20 | ||
go 1.21.0 | ||
|
||
require github.com/chenmingyong0423/gkit v0.0.3 // indirect | ||
require github.com/chenmingyong0423/gkit v0.0.4 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,10 @@ | ||
github.com/chenmingyong0423/gkit v0.0.3 h1:hjq6NjARJRiITclDsRDL3o+h/qeK5cwGrGng14ggsYY= | ||
github.com/chenmingyong0423/gkit v0.0.3/go.mod h1:vyxci/+5NnMMbp+DQPs94BUwawmbNJEK1o8ezlrS3eg= | ||
github.com/chenmingyong0423/gkit v0.0.4 h1:LEToNpfzAN3aCUxCRltfO5j7jhtRntKt9LvwzhPhayc= | ||
github.com/chenmingyong0423/gkit v0.0.4/go.mod h1:vyxci/+5NnMMbp+DQPs94BUwawmbNJEK1o8ezlrS3eg= | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= | ||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters