Clone this repo
git clone https://github.com/Sesame-Disk/cool-storage-api.git
cd cool-storage-api
Build the image
docker-compose build
Run as a container
docker-compose up
Now the server started on port :3001
Clone this repo
git clone https://github.com/Sesame-Disk/cool-storage-api.git
cd cool-storage-api
Install all the dependencies
go mod tidy
Create the configuration file
cd conf
vim cool-api.yaml
Use the cool-api.dist.yaml template file.
go run main.go
Now the server started on port :3001
Every name.go file must have a name_test.go where the tests for the respective functions of the name.go file must be
go test ./...
go test -v .\some_test.go
go test ./... --coverprofile=coverage.out
go tool cover --html=coverage.out
curl http://localhost:3001/api/v1/ping
output:
pong
curl -X POST http://localhost:3001/registrations -H "Content-Type: application/x-www-form-urlencoded" -d "username=john_doe&password=EXAMPLE_PASSWORD"
output:
Success
curl -d "username=john_doe&password=EXAMPLE_PASSWORD" http://localhost:3001/api/v1/auth-token/
output: {"token":"l7p81hy0iEPzKZY5l0SEfpiKecwGQ1aqsGO4DyYs"}
curl -H "Authorization: Token l7p81hy0iEPzKZY5l0SEfpiKecwGQ1aqsGO4DyYs" http://localhost:3001/api/v1/auth/ping/
output if token is valid:
pong
output if token not valid
invalid access token
output if token expired
the token is expired
curl -H "Authorization: Token 5DwfTS8iOkbV4LkyHUDucmdlLfMuyum8VBDTgz2j" http://localhost:3001/api/v1/account/info/
output example:
{
"avatar_url":"http://127.0.0.1:3000/media/avatars/default.png",
"contact_email":null,
"department":"",
"email":"john_doe",
"email_notification_interval":0,
"institution":"",
"is_staff":false,
"login_id":"",
"name":"john_doe",
"space_usage":"0.00%",
"total":0,
"usage":0
}
Please note: When using Golang token-based authentication in a production environment, you should always use SSL/TLS certificates to prevent attacks during token requests, and responses flow.
curl -X POST http://localhost:3001/api/v1/single/upload -F "file=@filename.extension" -H "uploader-file-name: filename.extension"
output example:
File filename upload successfully
curl -X POST http://localhost:3001/api/v1/single/download -F "archiveId=somerandomid" -F "fileName=filename.extenison"
output example:
download success
https://www.vultr.com/docs/implement-tokenbased-authentication-with-golang-and-mysql-8-server/