-
Notifications
You must be signed in to change notification settings - Fork 6
/
lowercasetext.go
39 lines (30 loc) · 861 Bytes
/
lowercasetext.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package handlers
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
"github.com/EngineerKamesh/igb/igweb/common"
)
func LowercaseTextTransformHandler(env *common.Env) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var s string
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Print("Encountered error when attempting to read the request body: ", err)
}
reqBodyString := string(reqBody)
err = json.Unmarshal([]byte(reqBodyString), &s)
if err != nil {
log.Print("Encountered error when attempting to unmarshal JSON: ", err)
}
textBytes, err := json.Marshal(strings.ToLower(s))
if err != nil {
log.Print("Encountered error when attempting ot marshal JSON: ", err)
}
fmt.Println("textBytes string: ", string(textBytes))
w.Write(textBytes)
})
}