Skip to content

Commit aa6ef1b

Browse files
author
cayan
committed
refactor: README.md
1 parent 7b55276 commit aa6ef1b

File tree

5 files changed

+85
-6
lines changed

5 files changed

+85
-6
lines changed

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ os?=$(shell go env GOOS)
1010
ARCH=$(arch)
1111
OS=$(os)
1212
CGO=1
13+
BIN_FOLDER=bin
1314
PLUGINS_FOLDER=plugins
1415
PLUGIN_GO_FILE=plugin.go
1516
PLUGIN_NAME=plugin.so
@@ -21,7 +22,6 @@ ERRORG_DIRECTORY= ~/.errorg
2122
init: go-plugin http-plugin # Build whole plugins
2223

2324

24-
2525
.PHONY: go-plugin
2626
go-plugin: # To build a golang standard errors plugin.
2727
@echo " > Building go-plugin..."
@@ -33,3 +33,11 @@ http-plugin: # To build a http errors plugin.
3333
@echo " > Building http-plugin..."
3434
chmod -R 700 ${CURDIR}/${PLUGINS_FOLDER}
3535
CGO_ENABLED=${CGO} GOOS=${OS} GOARCH=${ARCH} go build -buildmode=plugin -o ${CURDIR}/${PLUGINS_FOLDER}/http/${PLUGIN_NAME} ${PLUGINS_FOLDER}/http/${PLUGIN_GO_FILE}
36+
37+
38+
.PHONY: example
39+
example: # To example
40+
@echo " > Building example go app..."
41+
CGO_ENABLED=${CGO} GOOS=${OS} GOARCH=${ARCH} go build -o ${BIN_FOLDER}/errorg example/main.go
42+
chmod +x ${BIN_FOLDER}/errorg
43+
./${BIN_FOLDER}/errorg

README.md

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,28 @@
22

33
## Introduction
44

5-
errog helps to error handling for golang apps.
5+
errog helps to error handling for golang apps and thanks to golang/plugins it can be added the new plugin
6+
7+
The main purpose of this library is to manage all error codes from a common library.
8+
9+
10+
## Example
11+
12+
In order to see on example app make commands can be used like below:
13+
14+
```shell
15+
make init
16+
make example
17+
```
18+
19+
And example app returns like below:
20+
21+
Ex App Group is "http" and code is "401"
22+
23+
```json
24+
{"msg":"Although the HTTP standard specifies \"unauthorized\", semantically this response means \"unauthenticated\". That is, the client must authenticate itself to get the requested response."}
25+
```
26+
627

728

829
## Usage
@@ -29,6 +50,52 @@ func test() error {
2950
```
3051

3152

32-
3353
> [!NOTE]
3454
> "http" => group | "401" => code of group (For this ex it means http **401** error code.)
55+
56+
57+
## Plugins
58+
You can create a plugin for errorg. Errorg uses Golang plugins and some plugins created by default. If you want to further information for plugins check [this](https://pkg.go.dev/plugin) out
59+
60+
You can add the new plugin to under the **plugins** folder.
61+
Example plugin:
62+
63+
```go
64+
package main
65+
66+
type httpError struct {
67+
}
68+
69+
func (g httpError) GetErrorMap() map[string]interface{} {
70+
return map[string]interface{}{
71+
"400": struct {
72+
Message string `json:"msg"`
73+
}{"The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing)."},
74+
}
75+
}
76+
77+
var Group httpError
78+
```
79+
80+
Group represent the interface that will be implemented.
81+
82+
After that you need to add new make command to Makefile
83+
84+
Ex command:
85+
86+
```makefile
87+
http-plugin: # To build a http errors plugin.
88+
@echo " > Building http-plugin..."
89+
chmod -R 700 ${CURDIR}/${PLUGINS_FOLDER}
90+
CGO_ENABLED=${CGO} GOOS=${OS} GOARCH=${ARCH} go build -buildmode=plugin -o ${CURDIR}/${PLUGINS_FOLDER}/http/${PLUGIN_NAME} ${PLUGINS_FOLDER}/http/${PLUGIN_GO_FILE}
91+
```
92+
93+
plugin module waits *.so* files Therefore this command will be created the **plugin.so** file.
94+
95+
Lastly, you need to add new plugin infos to configs/config.yaml
96+
97+
```yaml
98+
plugins:
99+
- name: foo
100+
location: plugins/foo/plugin.so
101+
```

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.0.2

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ require (
1111
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1212
github.com/kr/pretty v0.3.1 // indirect
1313
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
14-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
14+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
1515
)

go.sum

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
22
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
33
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
45
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
56
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
7+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
8+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
69
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
710
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
811
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
@@ -13,7 +16,7 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/f
1316
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
1417
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
1518
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
16-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
17-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
19+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
20+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
1821
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1922
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)