mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 06:59:50 +02:00
restructured the project to comply community guideline, for others check release note
This commit is contained in:
20
internal/api/v1/utils/utils.go
Normal file
20
internal/api/v1/utils/utils.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func RespondJson(w http.ResponseWriter, data any, code ...int) error {
|
||||
if len(code) > 0 {
|
||||
w.WriteHeader(code[0])
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
j, err := json.MarshalIndent(data, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
} else {
|
||||
w.Write(j)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user