mirror of
https://github.com/Starlio-app/StarlioX
synced 2025-02-21 23:03:11 +03:00
rewritten from net/http to fiber, changed port from 8080, 4662 to one 3000
This commit is contained in:
parent
42f568cf85
commit
16301a3428
8 changed files with 102 additions and 47 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -2,17 +2,18 @@ package utils
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/Redume/EveryNasa/functions"
|
||||
"net/http"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func Message(status bool, message string) map[string]interface{} {
|
||||
return map[string]interface{}{"status": status, "message": message}
|
||||
}
|
||||
|
||||
func Respond(w http.ResponseWriter, data map[string]interface{}) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(data)
|
||||
func Respond(c *fiber.Ctx, data map[string]interface{}) {
|
||||
c.Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(c).Encode(data)
|
||||
if err != nil {
|
||||
functions.Logger(err.Error())
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue