Skip to content

Commit

Permalink
Implemented API Endpoint to modify the servers set language
Browse files Browse the repository at this point in the history
  • Loading branch information
confused-Techie committed Jan 5, 2022
1 parent a59ff48 commit e0e8c10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions GoPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func main() {
// For the proper filtering of items, and hopeful searching, here will be an api call for js to get all items as json
http.HandleFunc("/api/items", apiItemsHandler)
http.HandleFunc("/api/serversettings", apiServerSettingsHandler)
http.HandleFunc("/api/changelang", handler.ChangeLang) // /api/changelang?lang=en
http.HandleFunc("/api/usersettings", apiUserSettingsHandler)
http.HandleFunc("/api/usersettingswrite", model.UserSettingSet)
// Below will be API declarations used for plugins
Expand Down
21 changes: 21 additions & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"github.com/spf13/viper"
"io/ioutil"
"net/http"
modifySettings "github.com/confused-Techie/GoPage/modifySettings"
"encoding/json"
)

// UploadHandler is paired to http.HandleFunc("/upload", ) to handle the digestion of image uploads to GoPage
Expand Down Expand Up @@ -46,3 +48,22 @@ func UploadHandler(w http.ResponseWriter, r *http.Request) {
// After successfully uploading the file, redirect to the home page
http.Redirect(w, r, "/uploadpage", 301)
}

// ChangeLang is an API Endpoint to modify the server language whenever needed.
func ChangeLang(w http.ResponseWriter, r *http.Request) {
keys, ok := r.URL.Query()["lang"]
if !ok || len(keys[0]) < 1 {
fmt.Println("URL Param 'lang' is missing")
json.NewEncoder(w).Encode("URL Param 'lang' is missing")
}
newLang := keys[0]

modifySettings.SetLangEnv(newLang)
resp, err := modifySettings.DetermineLang()

if err != nil {
fmt.Println("Error Occured when setting Lang: ", err)
json.NewEncoder(w).Encode("Error Occured when setting Lang")
}
json.NewEncoder(w).Encode(resp)
}
2 changes: 1 addition & 1 deletion settings/serverSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"version": "0.3.1",
"author": "confused-Techie",
"lang": "en"
}
}

0 comments on commit e0e8c10

Please sign in to comment.