Try it on bbs-restful-api.herokuapp.com
- gin
- gorm
- gin-sessions
GET /posts
: 瀏覽目前的留言(不包含隱藏留言,預設30筆)GET /register
: 註冊帳號GET /login
: 登入帳號
POST /posts
: 創建留言POST /posts/:id/comments
: 回覆特定留言
GET /admin/posts
: 瀏覽目前的留言(包含隱藏留言,預設30筆)GET /admin/posts/search
: 搜尋留言內容PATCH /admin/posts/:id
: 隱藏/顯示特定留言PATCH /admin/users/:id
:停權/解封特定使用者
# You need to create a db user if you have't one
sudo -u postgres createuser -s <username>
export DATABASE_URL="your_postgredb_url"
export SESSION_KEY="session_store_secret_you_want"
export ADMIN_PASSWD="bbs_admin_password_you_want"
go run main.go
# You need to create a test db if you have't one
sudo -u postgres createdb bbstest
go test -count=1 ./...
Check out .github/workflows/main.yaml
to see how it works
Set DATABASE_URL
, SESSION_KEY
and ADMIN_PASSWD
as your app's Config Vars
curl -i -X GET -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/posts
curl -i -X POST -d '{"username":"test_login","password":"test_password"}' -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/register
cookie=$(curl -i -X POST -d '{"username":"test_login","password":"test_password"}' -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/login | grep -Po '(?<=Set-Cookie: ).+(?=\r)')
curl -i -X POST -d '{"title":"test_title2","content":"test_content2"}' --cookie "$cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/posts
curl -i -X POST -d '{"content":"test_comment"}' --cookie "$cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/posts/2/comments
admin_cookie=$(curl -i -X POST -d '{"username":"admin","password":'"\"$ADMIN_PASSWD\""'}' -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/login | grep -Po '(?<=Set-Cookie: ).+(?=\r)')
curl -i -X PATCH -d '{"active": false}' --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/users/2
curl -i -X PATCH -d '{"active": true}' --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/users/2
curl -i -X PATCH -d '{"hidden": true}' --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/posts/2
curl -i -X PATCH -d '{"hidden": false}' --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/posts/2
curl -i -X GET --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/posts
curl -i -X GET --cookie "$admin_cookie" -H 'Content-Type: application/json' bbs-restful-api.herokuapp.com/admin/posts/search?keyword="123"
- Use bcrypt on password accessing
- Deploy on cloud service
- Testing