Skip to content

Commit 8b1dad2

Browse files
committed
Add folder structure
1 parent 4a18a41 commit 8b1dad2

15 files changed

Lines changed: 318 additions & 11 deletions

File tree

api/.air.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
root = "."
2+
testdata_dir = "testdata"
3+
tmp_dir = "tmp"
4+
5+
[build]
6+
bin = "tmp\\main.exe"
7+
cmd = "go build -o ./tmp/main.exe ."
8+
delay = 1000
9+
exclude_dir = ["assets", "tmp", "vendor", "testdata"]
10+
exclude_file = []
11+
exclude_regex = ["_test.go"]
12+
exclude_unchanged = false
13+
follow_symlink = false
14+
full_bin = ""
15+
include_dir = []
16+
include_ext = ["go", "tpl", "tmpl", "html"]
17+
kill_delay = "0s"
18+
log = "build-errors.log"
19+
send_interrupt = false
20+
stop_on_error = true
21+
22+
[color]
23+
app = ""
24+
build = "yellow"
25+
main = "magenta"
26+
runner = "green"
27+
watcher = "cyan"
28+
29+
[log]
30+
time = false
31+
32+
[misc]
33+
clean_on_exit = false
34+
35+
[screen]
36+
clear_on_rebuild = false

api/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
docs
22
.env
33
*main.exe
4+
tmp

api/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ require (
88
github.com/gofiber/fiber/v2 v2.34.0
99
github.com/gofiber/swagger v0.0.1
1010
github.com/joho/godotenv v1.4.0
11+
github.com/rs/zerolog v1.26.1
1112
github.com/swaggo/swag v1.8.2
13+
go.opentelemetry.io/otel v1.7.0
1214
)
1315

1416
require (
@@ -27,6 +29,7 @@ require (
2729
github.com/valyala/bytebufferpool v1.0.0 // indirect
2830
github.com/valyala/fasthttp v1.37.0 // indirect
2931
github.com/valyala/tcplisten v1.0.0 // indirect
32+
go.opentelemetry.io/otel/trace v1.7.0 // indirect
3033
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
3134
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
3235
golang.org/x/tools v0.1.10 // indirect

api/go.sum

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY
1010
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
1111
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
1212
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
13+
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
1314
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
1415
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1516
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -19,6 +20,9 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
1920
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
2021
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
2122
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
23+
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
24+
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
25+
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
2226
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
2327
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
2428
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
@@ -34,11 +38,14 @@ github.com/go-openapi/swag v0.21.1 h1:wm0rhTb5z7qpJRHBdPOMuY4QjVUMbF6/kwoYeRAOrK
3438
github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
3539
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
3640
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
41+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
3742
github.com/gofiber/fiber/v2 v2.32.0/go.mod h1:CMy5ZLiXkn6qwthrl03YMyW1NLfj0rhxz2LKl4t7ZTY=
3843
github.com/gofiber/fiber/v2 v2.34.0 h1:96BJMw6uaxQhJsHY54SFGOtGgp9pgombK5Hbi4JSEQA=
3944
github.com/gofiber/fiber/v2 v2.34.0/go.mod h1:ozRQfS+D7EL1+hMH+gutku0kfx1wLX4hAxDCtDzpj4U=
4045
github.com/gofiber/swagger v0.0.1 h1:Qwt6uehJffeMG7zla3ampguOPtAW5K4xDAmpaL1qwXk=
4146
github.com/gofiber/swagger v0.0.1/go.mod h1:gal49FHSULvKAl9Ta+W7fRHdlTWhHPvArmsxKaIdLw4=
47+
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
48+
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
4249
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
4350
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=
4451
github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
@@ -68,17 +75,22 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJ
6875
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
6976
github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo=
7077
github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc=
78+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
7179
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7280
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
81+
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
82+
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
83+
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
7384
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
7485
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
7586
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
7687
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
7788
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7889
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7990
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
80-
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
8191
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
92+
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
93+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
8294
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 h1:+iNTcqQJy0OZ5jk6a5NLib47eqXK8uYcPX+O4+cBpEM=
8395
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2/go.mod h1:lKJPbtWzJ9JhsTN1k1gZgleJWY/cqq0psdoMmaThG3w=
8496
github.com/swaggo/swag v1.8.1/go.mod h1:ugemnJsPZm/kRwFUnzBlbHRd0JY9zE1M4F+uy2pAaPQ=
@@ -93,14 +105,20 @@ github.com/valyala/fasthttp v1.37.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxn
93105
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
94106
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
95107
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
108+
go.opentelemetry.io/otel v1.7.0 h1:Z2lA3Tdch0iDcrhJXDIlC94XE+bxok1F9B+4Lz/lGsM=
109+
go.opentelemetry.io/otel v1.7.0/go.mod h1:5BdUoMIz5WEs0vt0CUEMtSSaTSHBBVwrhnz7+nrD5xk=
110+
go.opentelemetry.io/otel/trace v1.7.0 h1:O37Iogk1lEkMRXewVtZ1BBTVn5JEp8GrJvP92bJqC6o=
111+
go.opentelemetry.io/otel/trace v1.7.0/go.mod h1:fzLSB9nqR2eXzxPXb2JW9IKE+ScyXA48yyE4TNvoHqU=
96112
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
97113
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
114+
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
98115
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
99116
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
100117
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
101118
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
102119
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
103120
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
121+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
104122
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
105123
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
106124
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
@@ -123,6 +141,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
123141
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
124142
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
125143
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
144+
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
126145
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
127146
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
128147
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
@@ -134,6 +153,7 @@ golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
134153
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
135154
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
136155
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
156+
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
137157
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
138158
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
139159
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

api/main.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,36 @@ package main
33
import (
44
"log"
55

6+
"github.com/NdoleStudio/http-sms-manager/pkg/di"
7+
68
_ "github.com/NdoleStudio/http-sms-manager/docs"
79
"github.com/gofiber/fiber/v2"
810
"github.com/gofiber/fiber/v2/middleware/logger"
911
"github.com/gofiber/swagger"
1012
)
1113

12-
// @title HTTP SMS API
13-
// @version 1.0
14-
// @description Sample API to send messages using android sms manager via HTTP
15-
// @termsOfService http://swagger.io/terms/
16-
// @contact.name HTTP SMS Support
14+
// @title HTTP SMS API
15+
// @version 1.0
16+
// @description API to send SMS messages using android [SmsManager](https://developer.android.com/reference/android/telephony/SmsManager) via HTTP
17+
//
18+
// @contact.name HTTP SMS Support
1719
// @contact.email supportd@httpsms.com
18-
// @license.name Apache 2.0
19-
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
20-
// @host api.httpsms.com
21-
// @BasePath /
20+
//
21+
// @license.name MIT
22+
// @license.url https://raw.githubusercontent.com/NdoleStudio/http-sms-manager/main/LICENSE
23+
//
24+
// @host api.httpsms.com
25+
// @BasePath /v1
2226
func main() {
2327
app := fiber.New()
2428

25-
// log requests/responses
2629
app.Use(logger.New())
2730

31+
container := di.NewContainer()
32+
33+
apiV1 := app.Group("v1")
34+
apiV1.Post("/messages/send", container.MessageHandler().Send)
35+
2836
app.Get("/*", swagger.HandlerDefault)
2937

3038
log.Println(app.Listen(":8000"))

api/pkg/di/container.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package di
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/NdoleStudio/http-sms-manager/pkg/handlers"
8+
"github.com/NdoleStudio/http-sms-manager/pkg/telemetry"
9+
"github.com/gofiber/fiber/v2"
10+
"github.com/rs/zerolog"
11+
)
12+
13+
// Container is used to resolve services at runtime
14+
type Container struct {
15+
logger telemetry.Logger
16+
messageHandler *handlers.MessageHandler
17+
}
18+
19+
// NewContainer creates a new dependency injection container
20+
func NewContainer() (container *Container) {
21+
return &Container{
22+
logger: logger().WithService(fmt.Sprintf("%T", container)),
23+
}
24+
}
25+
26+
// Logger creates a new instance of telemetry.Logger
27+
func (container Container) Logger() (l telemetry.Logger) {
28+
container.logger.Debug(fmt.Sprintf("creating %T", l))
29+
return logger()
30+
}
31+
32+
// MessageHandler creates a new instance of handlers.MessageHandler
33+
func (container *Container) MessageHandler() (handler *handlers.MessageHandler) {
34+
if container.messageHandler != nil {
35+
return container.messageHandler
36+
}
37+
38+
container.logger.Debug(fmt.Sprintf("creating %T", handler))
39+
40+
return handlers.NewMessageHandler()
41+
}
42+
43+
func logger() telemetry.Logger {
44+
hostname, _ := os.Hostname()
45+
fields := fiber.Map{
46+
"pid": os.Getpid(),
47+
"hostname": hostname,
48+
}
49+
return telemetry.NewZerologLogger(
50+
zerolog.New(
51+
zerolog.ConsoleWriter{
52+
Out: os.Stderr,
53+
},
54+
).With().Fields(fields).Timestamp().CallerWithSkipFrameCount(3),
55+
)
56+
}

api/pkg/entities/message.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package entities
2+
3+
// Message represents a message sent between 2 users
4+
type Message struct{}

api/pkg/events/event_dispatcher.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package events

api/pkg/handlers/handler.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package handlers
2+
3+
import (
4+
"net/url"
5+
6+
"github.com/gofiber/fiber/v2"
7+
)
8+
9+
// handler is the base struct for handling requests
10+
type handler struct{}
11+
12+
func (h *handler) responseBadRequest(c *fiber.Ctx, payload any) error {
13+
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
14+
"status": "error",
15+
"message": "The request isn't properly formed",
16+
"data": payload,
17+
})
18+
}
19+
20+
func (h *handler) responseInternalServerError(c *fiber.Ctx) error {
21+
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
22+
"status": "error",
23+
"message": "We ran into an internal error while handling the request.",
24+
"data": nil,
25+
})
26+
}
27+
28+
func (h *handler) responseForbidden(c *fiber.Ctx) error {
29+
return c.Status(fiber.StatusForbidden).JSON(fiber.Map{
30+
"status": "error",
31+
"message": fiber.ErrForbidden.Message,
32+
"data": nil,
33+
})
34+
}
35+
36+
func (h *handler) responseUnprocessableEntity(c *fiber.Ctx, errors url.Values, message string) error {
37+
return c.Status(fiber.StatusUnprocessableEntity).JSON(fiber.Map{
38+
"status": "error",
39+
"message": message,
40+
"data": errors,
41+
})
42+
}
43+
44+
func (h *handler) responseNotFound(c *fiber.Ctx, message string) error {
45+
return c.Status(fiber.StatusNotFound).JSON(fiber.Map{
46+
"status": "error",
47+
"message": message,
48+
"data": nil,
49+
})
50+
}
51+
52+
func (h *handler) responseOK(c *fiber.Ctx, message string, data interface{}) error {
53+
return c.Status(fiber.StatusOK).JSON(fiber.Map{
54+
"status": "success",
55+
"message": message,
56+
"data": data,
57+
})
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package handlers
2+
3+
import "github.com/gofiber/fiber/v2"
4+
5+
// MessageHandler handles message http requests.
6+
type MessageHandler struct {
7+
handler
8+
}
9+
10+
// NewMessageHandler creates a new MessageHandler
11+
func NewMessageHandler() *MessageHandler {
12+
return &MessageHandler{}
13+
}
14+
15+
// Send a new entities.Message
16+
// @Summary Send a new SMS message
17+
// @Description Add a new SMS message to be sent by the android phone
18+
// @Tags Messages
19+
// @Accept json
20+
// @Produce json
21+
// @Success 200 {object} responses.MessageResponse
22+
// @Router /messages/send [post]
23+
func (handler *MessageHandler) Send(c *fiber.Ctx) error {
24+
return nil
25+
}

0 commit comments

Comments
 (0)