Using gin, GORM, gocron and JWT tokens.
router.GET("/servers/get_hostname/:thresh", a.GetServerHostname)
router.GET("/servers", a.GetAllServer)
router.GET("/server/:id", a.GetServer)
router.POST("/servers/create", a.CreateServer)
router.PUT("/servers/:id/update_server", a.UpdateServer)
router.PUT("/servers/:id/disable", a.DisableServer)
router.PUT("/servers/:id/enable", a.EnableServer)
router.DELETE("/servers/:id", a.DeleteServer)
all the api with examples can be found under postman collection file.
Create server:
curl --location 'http://localhost:8004/servers/create' \
--header 'Content-Type: text/plain' \
--data '{
"Ip":"127.0.0.8",
"Hostname":"mta-prod-5",
"Active": false
}'
Search server by id:
curl --location 'http://localhost:8004/server/2'
go run main.go
To continuously connect to the application server, run the following command
nodemon --exec go run cmd/server/main.go --signal SIGTERM
nodemon --exec go run cmd/cron/cronjob.go --signal SIGTERM
To run test:
with coverage:
go test ./... -cover
To make them sorted and in an order by ID:
UPDATE servers m
SET id = sub.rn
from (SELECT id, row_number() OVER (ORDER BY id, id) AS rn FROM servers)sub
WHERE m.id = sub.id;
DB:
API for getting hostnames with threshold:
Code coverage:
Unit test coverage is 61.6%
. (red part-> not covered in unit test) only the main logic have been covered in the test cases.