up
This commit is contained in:
parent
17a9c5835e
commit
98a83549f0
9
serve.go
9
serve.go
@ -22,13 +22,16 @@ func (s *Server) Admin() *fiber.App {
|
|||||||
})
|
})
|
||||||
|
|
||||||
a.Post("/shorten", func(c *fiber.Ctx) error {
|
a.Post("/shorten", func(c *fiber.Ctx) error {
|
||||||
|
longUrl := string(c.Body())
|
||||||
shortUrl := c.Query("s")
|
shortUrl := c.Query("s")
|
||||||
if shortUrl == "" {
|
if shortUrl == "" {
|
||||||
shortUrl = s.serverGen.NextID()
|
shortUrl = s.serverGen.NextID()
|
||||||
}
|
}
|
||||||
longUrl := string(c.Body())
|
err := s.storage.Put(shortUrl, longUrl)
|
||||||
|
if err != nil {
|
||||||
return s.storage.Put(shortUrl, longUrl)
|
return err
|
||||||
|
}
|
||||||
|
return c.SendString(shortUrl)
|
||||||
})
|
})
|
||||||
|
|
||||||
return a
|
return a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user