Merge pull request #25 from sunboyy/finalize-v0.2

Update README.md for the latest features
This commit is contained in:
sunboyy 2021-06-05 16:43:36 +07:00 committed by GitHub
commit dd206ba46b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 358 additions and 132 deletions

128
CODE_OF_CONDUCT.md Normal file
View file

@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
surawich.lap@gmail.com.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

115
README.md
View file

@ -1,12 +1,12 @@
# repogen # repogen
<a href="https://github.com/sunboyy/repogen/actions?query=workflow%3Abuild"> <a href="https://github.com/sunboyy/repogen/actions?query=workflow%3Abuild" target="_blank">
<img src="https://github.com/sunboyy/repogen/workflows/build/badge.svg" alt="build status badge"> <img src="https://github.com/sunboyy/repogen/workflows/build/badge.svg" alt="build status badge">
</a> </a>
<a href="https://codecov.io/gh/sunboyy/repogen"> <a href="https://codecov.io/gh/sunboyy/repogen" target="_blank">
<img src="https://codecov.io/gh/sunboyy/repogen/branch/main/graph/badge.svg?token=9BD5Y8X7NO"/> <img src="https://codecov.io/gh/sunboyy/repogen/branch/main/graph/badge.svg?token=9BD5Y8X7NO"/>
</a> </a>
<a href="https://codeclimate.com/github/sunboyy/repogen/maintainability"> <a href="https://codeclimate.com/github/sunboyy/repogen/maintainability" target="_blank">
<img src="https://api.codeclimate.com/v1/badges/d0270245c28814200c5f/maintainability" /> <img src="https://api.codeclimate.com/v1/badges/d0270245c28814200c5f/maintainability" />
</a> </a>
@ -66,18 +66,7 @@ type UserRepository interface {
### Step 3: Run the repogen ### Step 3: Run the repogen
Run this command to generate a repository implementation from the specification. Run the repogen to generate a repository implementation from the interface. The following command is an example to generate `UserRepository` interface implementation defined in `examples/getting-started/user.go` to the destination file `examples/getting-started/user_repo.go`. See [Usage](#Usage) section below for more detailed information.
```
$ repogen -src=<src_file> -dest=<dest_file> -model=<model_struct> -repo=<repo_interface>
```
- `<src_file>` is the file that contains struct model and repository interface code
- `<dest_file>` is the destination path for the repository implementation to be generated
- `<model_struct>` is the name of the model struct for generating the repository
- `<repo_interface>` is the name of the repository interface to generate implementation from
For example:
``` ```
$ repogen -src=examples/getting-started/user.go -dest=examples/getting-started/user_repo.go \ $ repogen -src=examples/getting-started/user.go -dest=examples/getting-started/user_repo.go \
@ -88,6 +77,15 @@ You can also write the above command in the `go:generate` format inside Go files
## Usage ## Usage
### Running Options
The `repogen` command is used to generate source code for a given Go file containing repository interface to be implemented. Run `repogen -h` to see all available options while the necessary options for code generation are described as follows:
- `-src`: A Go file containing struct model and repository interface to be implemented
- `-dest`: A file to which to write the resulting source code. If not specified, the source code will be printed to the standard output.
- `-model`: The name of the base struct model that represents the data stored in MongoDB for a specific collection.
- `-repo`: The name of the repository interface that you want to be implemented.
### Method Definition ### Method Definition
To begin, your method name must be in pascal-case (camel-case with beginning uppercase letter). Repogen determines an operation for a method by getting the **first word** of the method name. There are 5 supported words which refer to 5 supported operations. To begin, your method name must be in pascal-case (camel-case with beginning uppercase letter). Repogen determines an operation for a method by getting the **first word** of the method name. There are 5 supported words which refer to 5 supported operations.
@ -114,11 +112,11 @@ InsertMany(ctx context.Context, models []*Model) ([]interface{}, error)
Repogen determines a single-entity operation or a multiple-entity by checking the second parameter and the first return value. However, the operation requires the first parameter to be of type `context.Context` and the second return value to be of type `error`. Repogen determines a single-entity operation or a multiple-entity by checking the second parameter and the first return value. However, the operation requires the first parameter to be of type `context.Context` and the second return value to be of type `error`.
As the `Insert` operation has a limited use case, we do not want to limit you on how you name your method. Any method that has the name starting with the word `Insert` is always valid. For example, you can name your method `InsertAWholeBunchOfDocuments` and it will work as long as you specify method parameters and returns correctly. As the `Insert` operation has a limited use case, we do not want to limit you on how you name your method. Any method that has the name starting with the word `Insert` is always valid. For example, you can name your method `InsertAWholeBunchOfDocuments` and it will work as long as you specify method parameters and return types correctly.
#### Find operation #### Find operation
A `Find` operation also has two modes like `Insert` operation: single-entity and multiple-entity. However `Find` operation can be very simple or complex depending on how complex the query is. In this section, we will show you how to write single-modes and multiple-entity modes of find method with a simple query. For more information about more complex queries, please consult the query specification section in this document. A `Find` operation also has two modes like `Insert` operation: single-entity and multiple-entity. However `Find` operation can be very simple or complex depending on how complex the query is. In this section, we will show you how to write single-modes and multiple-entity modes of find method with a simple query. For more information about more complex queries, please consult the [query specification](#query-specification) section in this document.
```go ```go
// FindByID gets a single document by ID // FindByID gets a single document by ID
@ -135,9 +133,35 @@ Repogen determines a single-entity or a multiple-entity operation by checking th
The requirement of the `Find` operation method is that there must be only two return values, the second return value must be of type `error` and the first method parameter must be of type `context.Context`. The requirement of number of method parameters depends on the query which will be described in the query specification section. The requirement of the `Find` operation method is that there must be only two return values, the second return value must be of type `error` and the first method parameter must be of type `context.Context`. The requirement of number of method parameters depends on the query which will be described in the query specification section.
Find operation also supports sorting results for both single-entity and multiple-entity operations. To sort, append the existing method name with `OrderBy`, followed by the field names to sort. The order will be default to ascending. In case that you want descending order, write `Desc` after the field name. For example:
```go
// This will sort results by age ascendingly
FindByCityOrderByAge(ctx context.Context, city string) ([]*Model, error)
// This will also sort results by age ascendingly
FindByCityOrderByAgeAsc(ctx context.Context, city string) ([]*Model, error)
// This will sort results by age descendingly
FindByCityOrderByAgeDesc(ctx context.Context, city string) ([]*Model, error)
```
#### Update operation #### Update operation
An `Update` operation also has two modes like `Insert` and `Find` operations: single-entity and multiple-entity. An `Update` operation also supports querying like `Find` operation. However, an `Update` operation requires more parameters than `Find` method, i.e. new values of updating fields. Specifying the query is the same as in `Find` method but specifying the updating fields are a little different. An `Update` operation also has single-entity and multiple-entity operations. An `Update` operation also supports querying like `Find` operation. Specifying the query is the same as in `Find` method. However, an `Update` operation requires more parameters than `Find` method depending on update type. There are two update types provided.
1. Model-type update
This type of update is for changing the whole model, replacing all the fields except the field with bson `omitempty` tag when the value is not provided. To write this type of update, write `Update` followed by query like in find method.
```go
// UpdateByID updates a single document by ID
UpdateByID(ctx context.Context, model *Model, id primitive.ObjectID) (bool, error)
```
2. Fields-type update
This type of update is for changing only some fields in the model. To write this type of update, specify the fields to update explicitly after `Update`. Updating multiple fields are allowed by concatinating each field name with `And` as follows:
```go ```go
// UpdateDisplayNameAndCityByID updates a single document with a new display name and // UpdateDisplayNameAndCityByID updates a single document with a new display name and
@ -149,9 +173,20 @@ UpdateDisplayNameAndCityByID(ctx context.Context, displayName string, city strin
UpdateGenderByCity(ctx context.Context, gender Gender, city string) (int, error) UpdateGenderByCity(ctx context.Context, gender Gender, city string) (int, error)
``` ```
Repogen determines a single-entity operation or a multiple-entity by checking the first return value. If it is of type `bool`, the method will be single-entity operation. If it is of type `int`, the method will be multiple-entity operation. For single-entity operation, the method returns true if there is a matching document. For multiple-entity operation, the integer return shows the number of matched documents. The update operator will be default to `$set` operator. In case that you want to use other operators, you can append the update field by the keyword that specifies the update operator. The current supported ones other than `$set` are `$push` and `$inc`. Write `Push` or `Inc` after the field name to apply those operators. Keep in mind that different operators requires different type of arguments such as an array-type for `Push` and a number-type for `Inc`.
The requirement of the `Update` operation method is that there must be only two return values, the second return value must be of type `error` and the first method parameter must be of type `context.Context`. The requirement of number of method parameters depends on the number of updating fields and the query. Updating fields must be directly after context parameter and query fields must be directly after updating fields. ```go
// UpdateConsentHistoryPushByID appends consentHistory to the ConsentHistory field
UpdateConsentHistoryPushByID(ctx context.Context, consentHistory ConsentHistory,
id primitive.ObjectID) (bool, error)
// UpdateAgeIncByID increments age value by `incAge`
UpdateAgeIncByID(ctx context.Context, incAge int, id primitive.ObjectID) (bool, error)
```
For all types of updates, repogen determines a single-entity operation or a multiple-entity by checking the first return value. If it is of type `bool`, the method will be single-entity operation. If it is of type `int`, the method will be multiple-entity operation. For single-entity operation, the method returns true if there is a matching document. For multiple-entity operation, the integer return shows the number of matched documents.
The requirement of the `Update` operation method is that there must be only two return values, the second return value must be of type `error` and the first method parameter must be of type `context.Context`. The requirement of number of method parameters depends on the update operation and the query.
#### Delete operation #### Delete operation
@ -170,7 +205,7 @@ DeleteAll(ctx context.Context) (int, error)
#### Count operation #### Count operation
A `Count` operation is also similar to `Find` operation except it has only multiple-entity mode. This means that the method returns are always the same for any count operations. The method name pattern and the parameters are the same as `Find` operation. A `Count` operation is also similar to `Find` operation except it has only multiple-entity mode and does not support sorting. This means that the method returns are always the same for any count operations. The method name pattern and the parameters are the same as `Find` operation without the sort parameters.
```go ```go
// CountByGender returns number of documents that match gender parameter // CountByGender returns number of documents that match gender parameter
@ -198,7 +233,7 @@ Assuming that the `City` field in the `UserModel` struct is of type `string` and
#### Comparators to each field #### Comparators to each field
When you specify the query like `ByAge`, it finds documents that contains age value **equal to** the provided parameter value. However, there are other types of comparators provided for you to use as follows. When you specify the query like `ByAge`, it finds documents that contains age value **equal to** the provided parameter value. However, there are other types of comparators supported in the following table:
| Keyword | Meaning | Sample | | Keyword | Meaning | Sample |
|--------------------|-----------------|--------------------------------------| |--------------------|-----------------|--------------------------------------|
@ -209,19 +244,51 @@ When you specify the query like `ByAge`, it finds documents that contains age va
| `GreaterThanEqual` | >= $1 | `FindByAgeGreaterThanEqual(ctx, $1)` | | `GreaterThanEqual` | >= $1 | `FindByAgeGreaterThanEqual(ctx, $1)` |
| `Between` | >= $1 and <= $2 | `FindByAgeBetween(ctx, $1, $2)` | | `Between` | >= $1 and <= $2 | `FindByAgeBetween(ctx, $1, $2)` |
| `In` | in slice $1 | `FindByCityIn(ctx, $1)` | | `In` | in slice $1 | `FindByCityIn(ctx, $1)` |
| `NotIn` | not in slice $1 | `FindByCityNotIn(ctx, $1)` |
| `True` | == `true` | `FindByEnabledTrue(ctx)` |
| `False` | == `false` | `FindByEnabledFalse(ctx)` |
To apply these comparators to the query, place these words after the field name such as `ByAgeGreaterThan`. You can also use comparators along with `And` and `Or` operators. For example, `ByGenderNotOrAgeLessThan` will apply `Not` comparator to the `Gender` field and `LessThan` comparator to the `Age` field. To apply these comparators to the query, place the keyword after the field name such as `ByAgeGreaterThan`. You can also use comparators along with `And` and `Or` operators. For example, `ByGenderNotOrAgeLessThan` will apply `Not` comparator to the `Gender` field and `LessThan` comparator to the `Age` field.
`Between` and `In` comparators are special in terms of parameter requirements. `Between` needs two parameters to perform the query and `In` needs a slice instead of its raw type. The example is provided below: `Between`, `In`, `NotIn`, `True` and `False` comparators are special in terms of parameter requirements. `Between` needs two parameters to perform the query, `In` and `NotIn` needs a slice instead of its raw type and `True` and `False` doesn't need any parameter. The example is provided below:
```go ```go
FindByAgeBetween(ctx context.Context, fromAge int, toAge int) ([]*UserModel, error) FindByAgeBetween(ctx context.Context, fromAge int, toAge int) ([]*UserModel, error)
FindByCityIn(ctx context.Context, cities []string) ([]*UserModel, error) FindByCityIn(ctx context.Context, cities []string) ([]*UserModel, error)
FindByCityNotIn(ctx context.Context, cities []string) ([]*UserModel, error)
FindByEnabledTrue(ctx context.Context) ([]*UserModel, error)
FindByEnabledFalse(ctx context.Context) ([]*UserModel, error)
``` ```
Assuming that the `Age` field in the `UserModel` struct is of type `int`, it requires that there must be two `int` parameters provided for `Age` field in the method. And assuming that the `City` field in the `UserModel` struct is of type `string`, it requires that the parameter that is provided to the query must be of slice type. Assuming that the `Age` field in the `UserModel` struct is of type `int`, it requires that there must be two `int` parameters provided for `Age` field in the method. And assuming that the `City` field in the `UserModel` struct is of type `string`, it requires that the parameter that is provided to the query must be of slice type.
### Field Referencing
To query, update or sort, you have to specify struct fields that you want to use. Repogen determines struct field by the field name. For example, the method name `FindByPhoneNumber` refer to the field named `PhoneNumber`. Repogen tries to find the properties of the struct field named `PhoneNumber` for further processing.
In the real world applications, you might want to refer to a struct field of another struct that is used in the base model, for example:
```go
type ContactModel struct {
Phone string `bson:"phone"`
Email string `bson:"email"`
}
type UserModel struct {
Contact ContactModel `bson:"contact"`
}
```
If you want to deeply refer to a struct field, you can do it by concatenating the field names that is the reference to the field you want. For example:
- To find by phone number, write `FindByContactPhone`
- To update phone number by ID, write `UpdateContactPhoneByID`
- To find all and sort results by phone number, write `FindAllOrderByContactPhone`
Deep referencing is supported for query fields, sort fields and update fields. However, the `inline` option for bson struct tag is not currently supported.
## License ## License
Licensed under [MIT](https://github.com/sunboyy/repogen/blob/main/LICENSE) Licensed under [MIT](https://github.com/sunboyy/repogen/blob/main/LICENSE)

20
go.mod
View file

@ -1,17 +1,15 @@
module github.com/sunboyy/repogen module github.com/sunboyy/repogen
go 1.15 go 1.16
require ( require (
github.com/aws/aws-sdk-go v1.37.3 // indirect github.com/aws/aws-sdk-go v1.38.52 // indirect
github.com/fatih/camelcase v1.0.0 github.com/fatih/camelcase v1.0.0
github.com/golang/snappy v0.0.2 // indirect github.com/klauspost/compress v1.12.3 // indirect
github.com/klauspost/compress v1.11.7 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.mongodb.org/mongo-driver v1.5.0 go.mongodb.org/mongo-driver v1.5.3
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a // indirect
golang.org/x/mod v0.4.2 // indirect golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b // indirect
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect golang.org/x/text v0.3.6 // indirect
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 // indirect golang.org/x/tools v0.1.2
golang.org/x/text v0.3.5 // indirect
golang.org/x/tools v0.1.0
) )

66
go.sum
View file

@ -1,7 +1,7 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
github.com/aws/aws-sdk-go v1.37.3 h1:1f0groABc4AuapskpHf6EBRaG2tqw0Sx3ebCMwfp1Ys= github.com/aws/aws-sdk-go v1.38.52 h1:7NKcUyTG/CyDX835kq04DDNe8vXaJhbGW8ThemHb18A=
github.com/aws/aws-sdk-go v1.37.3/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= github.com/aws/aws-sdk-go v1.38.52/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -35,8 +35,8 @@ github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGt
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw= github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA=
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
@ -48,14 +48,12 @@ github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqx
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg= github.com/klauspost/compress v1.12.3 h1:G5AfA94pHPysR56qqrkO2pxEexdDzrpFJ6yt/VqWxVU=
github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.12.3/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
@ -83,40 +81,41 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo= github.com/xdg-go/scram v1.0.2 h1:akYIkZ28e6A96dkWNJQu3nmCzH3YfwMPQExUYDaRv7w=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk=
go.mongodb.org/mongo-driver v1.5.0 h1:REddm85e1Nl0JPXGGhgZkgJdG/yOe6xvpXUcYK5WLt0= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4=
go.mongodb.org/mongo-driver v1.5.0/go.mod h1:boiGPFqyBs5R0R5qf2ErokGRekMfwn+MqKaUyHs7wy0= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.mongodb.org/mongo-driver v1.5.3 h1:wWbFB6zaGHpzguF3f7tW94sVE8sFl3lHx8OZx/4OuFI=
go.mongodb.org/mongo-driver v1.5.3/go.mod h1:gRXCHX4Jo7J0IJ1oDQyUxF7jfy19UfxniMS4xxMmUqw=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a h1:kr2P4QFmQr29mSLA43kwrOcgcReGTfbE9N577tCTuBc=
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b h1:uwuIcX0g4Yl1NC5XAz37xsr2lTtcqevgzYNVt49waME=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -124,31 +123,32 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181 h1:64ChN/hjER/taL4YJuA+gpLfIMT+/NFherRZixbxOhg= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210326220804-49726bf1d181/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b h1:qh4f65QIVFjq9eBURLEYWqaEXmOyqdUyiBSgaXWccWk=
golang.org/x/sys v0.0.0-20210601080250-7ecdf8ef093b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= golang.org/x/tools v0.1.2 h1:kRBLX7v7Af8W7Gdbbc908OJcdgtK8bOz9Uaj8/F1ACA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=

View file

@ -12,8 +12,6 @@ type ParsingError string
func (err ParsingError) Error() string { func (err ParsingError) Error() string {
switch err { switch err {
case UnsupportedReturnError:
return "this type of return is not supported"
case QueryRequiredError: case QueryRequiredError:
return "query is required" return "query is required"
case InvalidParamError: case InvalidParamError:
@ -28,13 +26,44 @@ func (err ParsingError) Error() string {
// parsing error constants // parsing error constants
const ( const (
UnsupportedReturnError ParsingError = "ERROR_UNSUPPORTED_RETURN"
QueryRequiredError ParsingError = "ERROR_QUERY_REQUIRED" QueryRequiredError ParsingError = "ERROR_QUERY_REQUIRED"
InvalidParamError ParsingError = "ERROR_INVALID_PARAM" InvalidParamError ParsingError = "ERROR_INVALID_PARAM"
InvalidUpdateFieldsError ParsingError = "ERROR_INVALID_UPDATE_FIELDS" InvalidUpdateFieldsError ParsingError = "ERROR_INVALID_UPDATE_FIELDS"
ContextParamRequiredError ParsingError = "ERROR_CONTEXT_PARAM_REQUIRED" ContextParamRequiredError ParsingError = "ERROR_CONTEXT_PARAM_REQUIRED"
) )
// NewUnsupportedReturnError creates unsupportedReturnError
func NewUnsupportedReturnError(givenType code.Type, index int) error {
return unsupportedReturnError{
GivenType: givenType,
Index: index,
}
}
type unsupportedReturnError struct {
GivenType code.Type
Index int
}
func (err unsupportedReturnError) Error() string {
return fmt.Sprintf("return type '%s' at index %d is not supported", err.GivenType.Code(), err.Index)
}
// NewOperationReturnCountUnmatchedError creates operationReturnCountUnmatchedError
func NewOperationReturnCountUnmatchedError(returnCount int) error {
return operationReturnCountUnmatchedError{
ReturnCount: returnCount,
}
}
type operationReturnCountUnmatchedError struct {
ReturnCount int
}
func (err operationReturnCountUnmatchedError) Error() string {
return fmt.Sprintf("operation requires return count of %d", err.ReturnCount)
}
// NewInvalidQueryError creates invalidQueryError // NewInvalidQueryError creates invalidQueryError
func NewInvalidQueryError(queryTokens []string) error { func NewInvalidQueryError(queryTokens []string) error {
return invalidQueryError{QueryString: strings.Join(queryTokens, "")} return invalidQueryError{QueryString: strings.Join(queryTokens, "")}

View file

@ -25,6 +25,16 @@ func TestError(t *testing.T) {
Error: spec.NewStructFieldNotFoundError([]string{"Phone", "Number"}), Error: spec.NewStructFieldNotFoundError([]string{"Phone", "Number"}),
ExpectedString: "struct field 'PhoneNumber' not found", ExpectedString: "struct field 'PhoneNumber' not found",
}, },
{
Name: "UnsupportedReturnError",
Error: spec.NewUnsupportedReturnError(code.SimpleType("User"), 0),
ExpectedString: "return type 'User' at index 0 is not supported",
},
{
Name: "OperationReturnCountUnmatchedError",
Error: spec.NewOperationReturnCountUnmatchedError(2),
ExpectedString: "operation requires return count of 2",
},
{ {
Name: "InvalidQueryError", Name: "InvalidQueryError",
Error: spec.NewInvalidQueryError([]string{"And"}), Error: spec.NewInvalidQueryError([]string{"And"}),

View file

@ -82,31 +82,27 @@ func (p interfaceMethodParser) parseInsertOperation(tokens []string) (Operation,
func (p interfaceMethodParser) extractInsertReturns(returns []code.Type) (QueryMode, error) { func (p interfaceMethodParser) extractInsertReturns(returns []code.Type) (QueryMode, error) {
if len(returns) != 2 { if len(returns) != 2 {
return "", UnsupportedReturnError return "", NewOperationReturnCountUnmatchedError(2)
} }
if returns[1] != code.SimpleType("error") { if returns[1] != code.SimpleType("error") {
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[1], 1)
} }
interfaceType, ok := returns[0].(code.InterfaceType) switch t := returns[0].(type) {
if ok { case code.InterfaceType:
if len(interfaceType.Methods) != 0 { if len(t.Methods) == 0 {
return "", UnsupportedReturnError
}
return QueryModeOne, nil return QueryModeOne, nil
} }
arrayType, ok := returns[0].(code.ArrayType) case code.ArrayType:
if ok { interfaceType, ok := t.ContainedType.(code.InterfaceType)
interfaceType, ok := arrayType.ContainedType.(code.InterfaceType) if ok && len(interfaceType.Methods) == 0 {
if !ok || len(interfaceType.Methods) != 0 {
return "", UnsupportedReturnError
}
return QueryModeMany, nil return QueryModeMany, nil
} }
}
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[0], 0)
} }
func (p interfaceMethodParser) parseFindOperation(tokens []string) (Operation, error) { func (p interfaceMethodParser) parseFindOperation(tokens []string) (Operation, error) {
@ -204,35 +200,31 @@ func (p interfaceMethodParser) splitQueryAndSortTokens(tokens []string) ([]strin
func (p interfaceMethodParser) extractModelOrSliceReturns(returns []code.Type) (QueryMode, error) { func (p interfaceMethodParser) extractModelOrSliceReturns(returns []code.Type) (QueryMode, error) {
if len(returns) != 2 { if len(returns) != 2 {
return "", UnsupportedReturnError return "", NewOperationReturnCountUnmatchedError(2)
} }
if returns[1] != code.SimpleType("error") { if returns[1] != code.SimpleType("error") {
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[1], 1)
} }
pointerType, ok := returns[0].(code.PointerType) switch t := returns[0].(type) {
if ok { case code.PointerType:
simpleType := pointerType.ContainedType simpleType := t.ContainedType
if simpleType == code.SimpleType(p.StructModel.Name) { if simpleType == code.SimpleType(p.StructModel.Name) {
return QueryModeOne, nil return QueryModeOne, nil
} }
return "", UnsupportedReturnError
}
arrayType, ok := returns[0].(code.ArrayType) case code.ArrayType:
if ok { pointerType, ok := t.ContainedType.(code.PointerType)
pointerType, ok := arrayType.ContainedType.(code.PointerType)
if ok { if ok {
simpleType := pointerType.ContainedType simpleType := pointerType.ContainedType
if simpleType == code.SimpleType(p.StructModel.Name) { if simpleType == code.SimpleType(p.StructModel.Name) {
return QueryModeMany, nil return QueryModeMany, nil
} }
return "", UnsupportedReturnError
} }
} }
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[0], 0)
} }
func splitByAnd(tokens []string) ([][]string, bool) { func splitByAnd(tokens []string) ([][]string, bool) {
@ -323,15 +315,15 @@ func (p interfaceMethodParser) parseCountOperation(tokens []string) (Operation,
func (p interfaceMethodParser) validateCountReturns(returns []code.Type) error { func (p interfaceMethodParser) validateCountReturns(returns []code.Type) error {
if len(returns) != 2 { if len(returns) != 2 {
return UnsupportedReturnError return NewOperationReturnCountUnmatchedError(2)
} }
if returns[0] != code.SimpleType("int") { if returns[0] != code.SimpleType("int") {
return UnsupportedReturnError return NewUnsupportedReturnError(returns[0], 0)
} }
if returns[1] != code.SimpleType("error") { if returns[1] != code.SimpleType("error") {
return UnsupportedReturnError return NewUnsupportedReturnError(returns[1], 1)
} }
return nil return nil
@ -339,11 +331,11 @@ func (p interfaceMethodParser) validateCountReturns(returns []code.Type) error {
func (p interfaceMethodParser) extractIntOrBoolReturns(returns []code.Type) (QueryMode, error) { func (p interfaceMethodParser) extractIntOrBoolReturns(returns []code.Type) (QueryMode, error) {
if len(returns) != 2 { if len(returns) != 2 {
return "", UnsupportedReturnError return "", NewOperationReturnCountUnmatchedError(2)
} }
if returns[1] != code.SimpleType("error") { if returns[1] != code.SimpleType("error") {
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[1], 1)
} }
simpleType, ok := returns[0].(code.SimpleType) simpleType, ok := returns[0].(code.SimpleType)
@ -356,7 +348,7 @@ func (p interfaceMethodParser) extractIntOrBoolReturns(returns []code.Type) (Que
} }
} }
return "", UnsupportedReturnError return "", NewUnsupportedReturnError(returns[0], 0)
} }
func (p interfaceMethodParser) validateContextParam() error { func (p interfaceMethodParser) validateContextParam() error {

View file

@ -1264,7 +1264,7 @@ func TestParseInterfaceMethod_Insert_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewOperationReturnCountUnmatchedError(2),
}, },
{ {
Name: "unsupported return types from insert method", Name: "unsupported return types from insert method",
@ -1275,7 +1275,7 @@ func TestParseInterfaceMethod_Insert_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.PointerType{ContainedType: code.SimpleType("UserModel")}, 0),
}, },
{ {
Name: "unempty interface return from insert method", Name: "unempty interface return from insert method",
@ -1290,7 +1290,7 @@ func TestParseInterfaceMethod_Insert_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.InterfaceType{}, 0),
}, },
{ {
Name: "error return not provided", Name: "error return not provided",
@ -1301,7 +1301,7 @@ func TestParseInterfaceMethod_Insert_Invalid(t *testing.T) {
code.InterfaceType{}, code.InterfaceType{},
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.InterfaceType{}, 1),
}, },
{ {
Name: "no context parameter", Name: "no context parameter",
@ -1353,7 +1353,7 @@ func TestParseInterfaceMethod_Insert_Invalid(t *testing.T) {
t.Run(testCase.Name, func(t *testing.T) { t.Run(testCase.Name, func(t *testing.T) {
_, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method) _, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method)
if err != testCase.ExpectedError { if err.Error() != testCase.ExpectedError.Error() {
t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err) t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err)
} }
}) })
@ -1372,7 +1372,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewOperationReturnCountUnmatchedError(2),
}, },
{ {
Name: "unsupported return types from find method", Name: "unsupported return types from find method",
@ -1383,7 +1383,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("UserModel"), 0),
}, },
{ {
Name: "error return not provided", Name: "error return not provided",
@ -1394,7 +1394,7 @@ func TestParseInterfaceMethod_Find_Invalid(t *testing.T) {
code.SimpleType("int"), code.SimpleType("int"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("int"), 1),
}, },
{ {
Name: "find method without query", Name: "find method without query",
@ -1675,7 +1675,7 @@ func TestParseInterfaceMethod_Update_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewOperationReturnCountUnmatchedError(2),
}, },
{ {
Name: "unsupported return types from update method", Name: "unsupported return types from update method",
@ -1686,7 +1686,7 @@ func TestParseInterfaceMethod_Update_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("float64"), 0),
}, },
{ {
Name: "error return not provided", Name: "error return not provided",
@ -1697,7 +1697,7 @@ func TestParseInterfaceMethod_Update_Invalid(t *testing.T) {
code.SimpleType("bool"), code.SimpleType("bool"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("bool"), 1),
}, },
{ {
Name: "update with no field provided", Name: "update with no field provided",
@ -1911,7 +1911,7 @@ func TestParseInterfaceMethod_Update_Invalid(t *testing.T) {
t.Run(testCase.Name, func(t *testing.T) { t.Run(testCase.Name, func(t *testing.T) {
_, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method) _, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method)
if err != testCase.ExpectedError { if err.Error() != testCase.ExpectedError.Error() {
t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err) t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err)
} }
}) })
@ -1930,7 +1930,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewOperationReturnCountUnmatchedError(2),
}, },
{ {
Name: "unsupported return types from delete method", Name: "unsupported return types from delete method",
@ -1941,7 +1941,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("float64"), 0),
}, },
{ {
Name: "error return not provided", Name: "error return not provided",
@ -1952,7 +1952,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
code.SimpleType("bool"), code.SimpleType("bool"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("bool"), 1),
}, },
{ {
Name: "delete method without query", Name: "delete method without query",
@ -2091,7 +2091,7 @@ func TestParseInterfaceMethod_Delete_Invalid(t *testing.T) {
t.Run(testCase.Name, func(t *testing.T) { t.Run(testCase.Name, func(t *testing.T) {
_, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method) _, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method)
if err != testCase.ExpectedError { if err.Error() != testCase.ExpectedError.Error() {
t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err) t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err)
} }
}) })
@ -2110,7 +2110,7 @@ func TestParseInterfaceMethod_Count_Invalid(t *testing.T) {
code.SimpleType("bool"), code.SimpleType("bool"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewOperationReturnCountUnmatchedError(2),
}, },
{ {
Name: "invalid integer return", Name: "invalid integer return",
@ -2121,7 +2121,7 @@ func TestParseInterfaceMethod_Count_Invalid(t *testing.T) {
code.SimpleType("error"), code.SimpleType("error"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("int64"), 0),
}, },
{ {
Name: "error return not provided", Name: "error return not provided",
@ -2132,7 +2132,7 @@ func TestParseInterfaceMethod_Count_Invalid(t *testing.T) {
code.SimpleType("bool"), code.SimpleType("bool"),
}, },
}, },
ExpectedError: spec.UnsupportedReturnError, ExpectedError: spec.NewUnsupportedReturnError(code.SimpleType("bool"), 1),
}, },
{ {
Name: "count method without query", Name: "count method without query",
@ -2222,7 +2222,7 @@ func TestParseInterfaceMethod_Count_Invalid(t *testing.T) {
t.Run(testCase.Name, func(t *testing.T) { t.Run(testCase.Name, func(t *testing.T) {
_, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method) _, err := spec.ParseInterfaceMethod(structs, structModel, testCase.Method)
if err != testCase.ExpectedError { if err.Error() != testCase.ExpectedError.Error() {
t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err) t.Errorf("\nExpected = %+v\nReceived = %+v", testCase.ExpectedError, err)
} }
}) })

16
main.go
View file

@ -15,12 +15,18 @@ import (
"github.com/sunboyy/repogen/internal/spec" "github.com/sunboyy/repogen/internal/spec"
) )
const version = "" const usageText = `repogen generates MongoDB repository implementation from repository interface
Find more information at: https://github.com/sunboyy/repogen
Supported options:`
const version = "v0.2.0"
func main() { func main() {
flag.Usage = printUsage flag.Usage = printUsage
versionPtr := flag.Bool("version", false, "print repogen version") versionPtr := flag.Bool("version", false, "print version of repogen")
sourcePtr := flag.String("src", "", "source file") sourcePtr := flag.String("src", "", "source file")
destPtr := flag.String("dest", "", "destination file") destPtr := flag.String("dest", "", "destination file")
modelPtr := flag.String("model", "", "model struct name") modelPtr := flag.String("model", "", "model struct name")
@ -70,16 +76,12 @@ func main() {
} }
func printUsage() { func printUsage() {
fmt.Println("Usage of repogen") fmt.Println(usageText)
flag.PrintDefaults() flag.PrintDefaults()
} }
func printVersion() { func printVersion() {
if version != "" {
fmt.Println(version) fmt.Println(version)
} else {
fmt.Println("(devel)")
}
} }
func generateFromRequest(fileName, structModelName, repositoryInterfaceName string) (string, error) { func generateFromRequest(fileName, structModelName, repositoryInterfaceName string) (string, error) {