rewritten from net/http to fiber, changed port from 8080, 4662 to one 3000

This commit is contained in:
Данил 2022-10-23 15:26:51 +03:00
parent 42f568cf85
commit 16301a3428
8 changed files with 102 additions and 47 deletions

View file

@ -1,16 +1,16 @@
package controllers
import (
"net/http"
"os"
"os/user"
"strings"
"github.com/Redume/EveryNasa/api/utils"
"github.com/Redume/EveryNasa/functions"
"github.com/gofiber/fiber/v2"
)
var CreateLabel = func(w http.ResponseWriter, r *http.Request) {
var CreateLabel = func(c *fiber.Ctx) error {
u, err := user.Current()
if err != nil {
functions.Logger(err.Error())
@ -28,5 +28,6 @@ var CreateLabel = func(w http.ResponseWriter, r *http.Request) {
functions.Logger(err.Error())
}
utils.Respond(w, utils.Message(true, "The shortcut was successfully created"))
utils.Respond(c, utils.Message(true, "The shortcut was successfully created"))
return nil
}

View file

@ -1,27 +1,28 @@
package controllers
import (
"net/http"
"github.com/Redume/EveryNasa/api/utils"
"github.com/Redume/EveryNasa/functions"
"github.com/gofiber/fiber/v2"
"github.com/reujab/wallpaper"
)
var WallpaperUpdate = func(w http.ResponseWriter, r *http.Request) {
var WallpaperUpdate = func(c *fiber.Ctx) error {
var url string
url = r.FormValue("url")
url = c.FormValue("url")
if url == "" {
utils.Respond(w, utils.Message(false, "URL is required"))
return
utils.Respond(c, utils.Message(false, "URL is required"))
return nil
}
err := wallpaper.SetFromURL(url)
if err != nil {
functions.Logger(err.Error())
utils.Respond(w, utils.Message(false, "An error occurred while setting the wallpaper"))
return
utils.Respond(c, utils.Message(false, "An error occurred while setting the wallpaper"))
return nil
}
utils.Respond(w, utils.Message(true, "Wallpaper successfully updated"))
utils.Respond(c, utils.Message(true, "Wallpaper successfully updated"))
return nil
}