Refactor apiTest into Status.go

This commit is contained in:
Kleissner
2021-09-15 16:29:26 +02:00
parent 16e9c0e67f
commit 67bf27a4af
2 changed files with 14 additions and 11 deletions

View File

@@ -21,8 +21,15 @@ import (
// Router can be used to register additional API functions
var Router *mux.Router
// WSUpgrader can be used to provide web sockets. It uses all default options and allows all requests.
var WSUpgrader = websocket.Upgrader{}
// WSUpgrader is used for websocket functionality. It allows all requests.
var WSUpgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
// allow all connections by default
return true
},
}
// Start starts the API. ListenAddresses is a list of IP:Ports
func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKey string, TimeoutRead, TimeoutWrite time.Duration) {
@@ -30,10 +37,6 @@ func Start(ListenAddresses []string, UseSSL bool, CertificateFile, CertificateKe
return
}
WSUpgrader.CheckOrigin = func(r *http.Request) bool {
return true
}
Router = mux.NewRouter()
Router.HandleFunc("/test", apiTest).Methods("GET")
@@ -107,8 +110,3 @@ func DecodeJSON(w http.ResponseWriter, r *http.Request, data interface{}) (err e
return nil
}
func apiTest(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}

View File

@@ -13,6 +13,11 @@ import (
"github.com/PeernetOfficial/core"
)
func apiTest(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}
type apiResponseStatus struct {
Status int `json:"status"` // Status code: 0 = Ok.
IsConnected bool `json:"isconnected"` // Whether connected to Peernet.