Init commit
Resolved conflict
This commit is contained in:
1
server/SERVER.md
Normal file
1
server/SERVER.md
Normal file
@@ -0,0 +1 @@
|
||||
# Go Backend Server Information.
|
||||
5
server/src/go.mod
Normal file
5
server/src/go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module ghostrunner-server
|
||||
|
||||
go 1.24.3
|
||||
|
||||
require github.com/gorilla/mux v1.8.1
|
||||
2
server/src/go.sum
Normal file
2
server/src/go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
5
server/src/main.go
Normal file
5
server/src/main.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
0
server/src/modules/restapi/handlers.go
Normal file
0
server/src/modules/restapi/handlers.go
Normal file
46
server/src/modules/restapi/init.go
Normal file
46
server/src/modules/restapi/init.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMessage = "GhostRunner Server, HTTP REST API. Version: 0.0.1."
|
||||
)
|
||||
|
||||
func rootEndpointHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
log.Println("ROOT HIT") //Comment out later, for debugging purposes
|
||||
json.NewEncoder(w).Encode(infoResponse{
|
||||
Status: http.StatusOK,
|
||||
Message: defaultMessage,
|
||||
})
|
||||
}
|
||||
|
||||
func _initApiServer(secureServer bool, apiKey, apiCert, apiPort string) {
|
||||
apiRouter := mux.NewRouter().StrictSlash(true) // Initialize the HTTP REST API Router.
|
||||
|
||||
apiRouter.HandleFunc("/", rootEndpointHandler).Methods("GET")
|
||||
|
||||
if secureServer { // If a secured server is wanted. Use the specified certificate files.
|
||||
httpServer := &http.Server{
|
||||
Addr: apiPort, // Specify the desired HTTPS port.
|
||||
Handler: apiRouter, // Specify the above created handler.
|
||||
TLSConfig: &tls.Config{
|
||||
Certificates: []tls.Certificate{ // Load the certificate and private key.
|
||||
loadTLSCertificate(apiCert, apiKey),
|
||||
},
|
||||
},
|
||||
}
|
||||
go httpServer.ListenAndServeTLS("", "")
|
||||
} else {
|
||||
go http.ListenAndServe(":"+apiPort, apiRouter) // Transform string slightly to make the expected format.
|
||||
}
|
||||
}
|
||||
6
server/src/modules/restapi/structs.go
Normal file
6
server/src/modules/restapi/structs.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package restapi
|
||||
|
||||
type infoResponse struct {
|
||||
Status int `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
14
server/src/modules/restapi/utilities.go
Normal file
14
server/src/modules/restapi/utilities.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"log"
|
||||
)
|
||||
|
||||
func loadTLSCertificate(certFile, keyFile string) tls.Certificate {
|
||||
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return cert
|
||||
}
|
||||
Reference in New Issue
Block a user