Update Server API and Add README.md
This commit is contained in:
parent
35e7487031
commit
73d9f2b95c
2 changed files with 16 additions and 4 deletions
11
README.md
Normal file
11
README.md
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# fastbin: a text sharing application
|
||||
|
||||
A text sharing application made with microservice architecture in golang.
|
||||
Services:
|
||||
- API Server (Read and Write)
|
||||
- Custom Key Generator Service
|
||||
- Database Service
|
||||
|
||||
To-do:
|
||||
- Add data deletion service which removes data after certain time.
|
||||
- Make key generator service faster and scalable with bloom filter and redis caching.
|
||||
|
|
@ -46,8 +46,8 @@ func NewAPIServer(port int) *http.Server {
|
|||
s := APIServer{db: db}
|
||||
|
||||
r := gin.Default()
|
||||
r.POST("/", s.write)
|
||||
r.GET("/:key", s.read)
|
||||
r.POST("/write", s.write)
|
||||
r.GET("/read/:key", s.read)
|
||||
|
||||
server := &http.Server{
|
||||
Addr: fmt.Sprintf(":%d", port),
|
||||
|
|
@ -64,11 +64,12 @@ func (as *APIServer) read(gc *gin.Context) {
|
|||
res := as.db.First(&paste, "id = ?", key)
|
||||
if res.Error != nil {
|
||||
gc.JSON(http.StatusNotFound, gin.H{
|
||||
"message": "Not Found.",
|
||||
"error": "Not Found.",
|
||||
"text": "",
|
||||
})
|
||||
} else {
|
||||
gc.JSON(http.StatusOK, gin.H{
|
||||
"message": paste.Text,
|
||||
"text": paste.Text,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue