mirror of
https://github.com/akyaiy/GoSally-mvp.git
synced 2026-01-03 08:12:25 +00:00
- Change package name general_server to gateway - Changing the structure of directories and packages - Adding vendor to the project
40 lines
731 B
Go
40 lines
731 B
Go
package rpc
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
const (
|
|
ErrParseError = -32700
|
|
ErrParseErrorS = "Parse error"
|
|
|
|
ErrInvalidRequest = -32600
|
|
ErrInvalidRequestS = "Invalid Request"
|
|
|
|
ErrMethodNotFound = -32601
|
|
ErrMethodNotFoundS = "Method not found"
|
|
|
|
ErrInvalidParams = -32602
|
|
ErrInvalidParamsS = "Invalid params"
|
|
|
|
ErrInternalError = -32603
|
|
ErrInternalErrorS = "Internal error"
|
|
|
|
ErrContextVersion = -32010
|
|
ErrContextVersionS = "Invalid context version"
|
|
)
|
|
|
|
func WriteRouterError(w http.ResponseWriter, status int, e *RPCError) error {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.WriteHeader(status)
|
|
|
|
data, err := json.Marshal(e)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = w.Write(data)
|
|
return err
|
|
}
|