Skip to content

Commit

Permalink
feat: remove id generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DenChenn committed Sep 14, 2023
1 parent 01e8b35 commit 98e5a91
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ All generated errors implement `blunder.OrdinaryError` interface, which contains
```go
ordinaryError, ok := err.(blunder.OrdinaryError)
if ok {
fmt.Println(ordinaryError.GetId())
fmt.Println(ordinaryError.GetMessage())
}
```
6 changes: 0 additions & 6 deletions internal/codegen/cmd/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,6 @@ var Gen = &cli.Command{
for _, detail := range blunderConfig.Details {
errorFilePath := filepath.Join(generatedRootPath, detail.Package, constant.ErrorFileName)

// generate id for this error according to file path + code
for i := range detail.Errors {
id := util.GenerateRandomId()
detail.Errors[i].Id = id
}

if err := template.Generate(errorFilePath, constant.ErrorFileTemplateFileName, &detail); err != nil {
return util.PrintErrAndReturn(err.Error())
}
Expand Down
1 change: 0 additions & 1 deletion internal/codegen/model/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type Detail struct {
}

type ErrorDescription struct {
Id string `yaml:"id"`
Code string `yaml:"code"`
HttpStatusCode int `yaml:"http_status_code"`
GrpcStatusCode int `yaml:"grpc_status_code"`
Expand Down
14 changes: 0 additions & 14 deletions internal/codegen/template/error.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
)

type {{ .Package }} struct {
Id string `json:"id"`
HttpStatusCode int `json:"http_status_code"`
GrpcStatusCode int `json:"grpc_status_code"`
ErrorCode string `json:"error_code"`
Expand All @@ -18,7 +17,6 @@ type {{ .Package }} struct {
var (
{{- range .Errors }}
{{ .Code }} = &{{ $.Package }}{
Id: "{{ .Id }}",
HttpStatusCode: {{ .HttpStatusCode }},
GrpcStatusCode: {{ .GrpcStatusCode }},
ErrorCode: "{{ .Code }}",
Expand All @@ -38,10 +36,6 @@ func (e *{{ .Package }}) Error() string {
return e.Message
}

func (e *{{ .Package }}) GetId() string {
return e.Id
}

func (e *{{ .Package }}) GetHttpStatusCode() int {
return e.HttpStatusCode
}
Expand All @@ -65,11 +59,3 @@ func (e *{{ .Package }}) Wrap(err error) {
func (e *{{ .Package }}) Unwrap() error {
return e.Err
}

func (e *{{ .Package }}) Is(err error) bool {
typedErr, ok := err.(*{{ .Package }})
if ok {
return typedErr.GetId() == e.GetId()
}
return false
}
11 changes: 0 additions & 11 deletions internal/util/id.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/blunder/blunder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package blunder

type OrdinaryError interface {
Error() string
GetId() string
GetHttpStatusCode() int
GetGrpcStatusCode() int
GetErrorCode() string
Expand Down

0 comments on commit 98e5a91

Please sign in to comment.