BREAKING CHANGE: Rename http module to webutils
This commit is contained in:
parent
9b6664399f
commit
4612ee993e
5 changed files with 21 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
|||
package http
|
||||
package webutils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package http
|
||||
package webutils
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package http
|
||||
package webutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
|
17
http/json.go
Normal file
17
http/json.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
package webutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func SendJson(w http.ResponseWriter, data any) error {
|
||||
encoded, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
fmt.Fprint(w, string(encoded))
|
||||
return nil
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package http
|
||||
package webutils
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
|
Loading…
Reference in a new issue