Session Management Service is a Golang based application to create, destroy, extend and list sessions using REST APIs.
Use go command to build service. go build generates an executable based on the operating system.
go build
Use below command to start the service
.\SMS.exe -PeriodicTimer=300
PeriodicTimer=300 is the configurable duration to remove stale sessions. Default value is 300. Accepts value between 0 to 600 ( in seconds).
Expiry field indicates TTL value.
curl -i -X POST http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"expiry":100}'
curl -i -X POST http://localhost:7443/sessionManagement
$ curl -i -X POST http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"expiry":50}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 32 100 19 100 13 593 406 --:--:-- --:--:-- --:--:-- 1032HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Mon, 07 Jun 2021 18:02:42 GMT
Content-Length: 19
{"responseCode":0}
UUID field holds the session identifier generated by service.
curl -i -X DELETE http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"UUID":"8dd478e8-c7ba-11eb-b589-00059a3c7a00"}'
$ curl -i -X DELETE http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"UUID":"e77b2b42-c700-11eb-9563-00059a3c7a00"}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 66 100 19 100 47 760 1880 --:--:-- --:--:-- --:--:-- 2640HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Sun, 06 Jun 2021 19:55:22 GMT
Content-Length: 19
{"responseCode":0}
uuid field holds the session identifier generated by service. duration field holds TTL value to be extended
curl -i -X PUT http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"uuid":"8dd478e8-c7ba-11eb-b589-00059a3c7a00", "duration": 150}'
$ curl -i -X PUT http://localhost:7443/sessionManagement -H 'Content-Type:application/json' -d '{"uuid":"3667f4f5-c702-11eb-93bd-00059a3c7a00", "duration": 150}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 83 100 19 100 64 2714 9142 --:--:-- --:--:-- --:--:-- 13833HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Sun, 06 Jun 2021 20:04:40 GMT
Content-Length: 19
{"responseCode":0}
Returns list of all active sessions and remaining TTL.
curl -i -X GET http://localhost:7443/sessionManagement
curl -i -X GET http://localhost:7443/sessionManagement
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 126 100 126 0 0 14000 0 --:--:-- --:--:-- --:--:-- 15750HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Sun, 06 Jun 2021 19:54:01 GMT
Content-Length: 126
[{"uuid":"e5c5495c-c700-11eb-9563-00059a3c7a00","duration":42},{"uuid":"e77b2b42-c700-11eb-9563-00059a3c7a00","duration":55}]
Following 3rd party packages have been used
- Echo labstack -> github.com/labstack/echo
- uuid package -> github.com/satori/go.uuid