ninjakx / mta-hosting-optimizer

A CRUD web app for hosted servers and fetching active server based on threshold.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mta-hosting-optimizer

Hits

Using gin, GORM, gocron and JWT tokens.

API

	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.

CURL

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'

RUN:

go run main.go

To continuously connect to the application server, run the following command

to run server:

nodemon --exec go run cmd/server/main.go --signal SIGTERM

to run cron:

nodemon --exec go run cmd/cron/cronjob.go --signal SIGTERM

To run test:

with coverage:

go test ./... -cover

PostgresSQL DB:

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.

About

A CRUD web app for hosted servers and fetching active server based on threshold.


Languages

Language:Go 99.9%Language:Shell 0.1%