A song data API build with Go and MongoDB.
This API is used by Caten-Music.
cp .env.example .env
Remember to update the .env
file with your own environment variables.
docker-compose -f docker-compose.dev.yaml up --build
-
Clone repository to your
$GOPATH/src
-
Set your local environment variables in
.env
.
You can quickly use the example to build one:cp .env.example .env
-
Install the dependencies
go get
-
Run the service
go run main.go
-
"/api/songs"
: get all songs from the database. -
"/api/songs/sid/{sid0+sid1+sid2+...}"
: get songs by multiplesid
, splited allsid
by"+"
. -
"/api/songs/search?lang={lang}&c={c}&to={to}&title={title}&lyrics={lyrics}&test=0"
: search songs by multiple arguments.-
lang
: language -"Chinese"
and"Taiwanese"
. -
c
: collection - from1
to11
. -
title
: title - the route keywords are splited by"+"
. -
to
: tonality - ex."C"
-
lyrics
: lyrics - the route keywords are splited by"+"
. -
test
: test mode - for development, normal user please set it to0
.
-
-
"/api/songs/random/{r}"
: get random songs by given a amountr
.
-
Need token for authority
-
"/api/songs/sid/{sid}"
: update a song by its{sid}
from the input body raw.
Document todo...
Document todo...
https://church-music-api.herokuapp.com/api/songs/sid/1010066+1010050+1003001
Response:
[{
"sid": "1010066",
"num_c": "10",
"num_i": "66",
"title": "前來敬拜",
"album": "讚美之泉20-新的事將要成就,6",
"tonality": "G",
"year": "2015",
"language": "Chinese",
},
{
"sid": "1010050",
"num_c": "10",
"num_i": "50",
"title": "當我謙卑來到主前",
"tonality": "G",
},
{
"sid": "1003001",
"num_c": "3",
"num_i": "1",
"title": "主愛有多少",
"tonality": "Eb",
}]
https://church-music-api.herokuapp.com/api/songs/search?lang=Chinese&c=7&to=A&title=來+歡&lyrics=眼睛+傷心&test=0
Response:
[{
"title": "我真歡喜來讚美你",
"num_c": "7",
"num_i": "71",
"sid": "1007071",
"language": "Chinese",
"tonality": "A",
"album": "約書亞02-祂的國度,祂的榮耀,1",
"lyrics": [
"p",
"睜開眼睛,感覺好熟悉,在你面前,",
"一切都不會在意,拋開憂慮,煩惱傷心,",
"現在只想和你一起,哦,我真歡喜來讚美你。",
]
}]
https://church-music-api.herokuapp.com/api/songs/sid/1010066
Body raw:
{
"tonality": "GGG",
"year": "200015",
"language": "Japanese"
}
Response:
{
"MatchedCount": 1,
"ModifiedCount": 1,
"UpsertedCount": 0,
"UpsertedID": null
}
The new data in the db:
[{
"sid": "1010066",
"num_c": "10",
"num_i": "66",
"title": "前來敬拜",
"album": "讚美之泉20-新的事將要成就,6",
"tonality": "GGG",
"year": "200015",
"language": "Japanese",
"lyrics": ...
}]
- 1000: Successful
- 1100: Render token error
- 1110: Token error
- 1120: Token has no authority
- 1200: Request body raw error
- 1300: Wrong information in request data
- 1400: Data already existed in DB, cannot create the same one
- 1410: Created song error by unknown reason
- 1510: Deleted song error by unknown reason
- 1600: No result found in DB
- 1700: Format error
- 1800: Wrong query data
- 1900: Updated song error by unknown reason