Skip to content

ragoncsa/todo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

todo

Overview

This is a sample application for REST service development with golang. Libraries used:

Alt text

Run from container

To build

docker build -t todo .

Docker-compose starts the built container with a database

docker-compose up

Go to Swagger UI http://localhost:8080/swagger/index.html

Reset the database

docker-compose down --volumes

Run without container

Start dependencies

docker-compose up db
opa build authz -o authz/bundle.tar.gz --ignore 'taskservice_authz_test.rego'
docker-compose up bundle_server
docker-compose up opa

To access the database:

$ docker exec -it todo_db_1 /bin/bash                               
root@187961c81d2e:/# psql -U postgres
psql (14.2 (Debian 14.2-1.pgdg110+1))
Type "help" for help.

Start the server

go run main.go

Go to Swagger UI http://localhost:8080/swagger/index.html

Testing

Test the application

go test ./...

Test the authorization rules

Run unit tests

opa test authz -v --ignore '*.tar.gz'

Test rules on the server

echo "{\"input\": {\"method\":\"POST\",\"owner\":\"johndoe\",\"path\":[\"tasks\"],\"user\":\"johndoe\"}}" \
| http -v POST http://127.0.0.1:8181/v1/data/authz

Generate OpenAPI spec

swag init

For more see: https://github.com/swaggo/gin-swagger