Initial commit
This commit is contained in:
Executable
+10
@@ -0,0 +1,10 @@
|
||||
package behaivor
|
||||
|
||||
import "log"
|
||||
|
||||
// Crash the program if an error exists. Anxiety before panic
|
||||
func Anxiety(prefixMessage string, err error) {
|
||||
if err != nil {
|
||||
log.Fatalf("%v:\n\t%v", prefixMessage, err)
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"go_project/pkg/behaivor"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Verification of the existence of a program with an emergency termination in case of an error
|
||||
func MustIsNotExist(filename string) (result bool) {
|
||||
_, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
result = os.IsNotExist(err)
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
if result == false {
|
||||
behaivor.Anxiety("Error checking the existence of the file", err)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Create a file with truncated data
|
||||
func MustCreate(filename string) {
|
||||
file, err := os.Create(filename)
|
||||
behaivor.Anxiety("File creating error", err)
|
||||
file.Close()
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
package information
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/gorilla/mux"
|
||||
"log"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Following prints all of the registered routes
|
||||
func AboutRoute(route *mux.Route, _ *mux.Router, _ []*mux.Route) error {
|
||||
pathTemplate, err := route.GetPathTemplate()
|
||||
|
||||
var buffer bytes.Buffer
|
||||
|
||||
if err == nil {
|
||||
buffer.WriteString("\n\t")
|
||||
buffer.WriteString("ROUTE: ")
|
||||
buffer.WriteString(pathTemplate)
|
||||
}
|
||||
pathRegexp, err := route.GetPathRegexp()
|
||||
if err == nil {
|
||||
buffer.WriteString("\n\t")
|
||||
buffer.WriteString("Path regexp: ")
|
||||
buffer.WriteString(pathRegexp)
|
||||
}
|
||||
queriesTemplates, err := route.GetQueriesTemplates()
|
||||
if err == nil {
|
||||
buffer.WriteString("\n\t")
|
||||
buffer.WriteString("Queries templates: ")
|
||||
buffer.WriteString(strings.Join(queriesTemplates, ","))
|
||||
}
|
||||
queriesRegexps, err := route.GetQueriesRegexp()
|
||||
if err == nil {
|
||||
buffer.WriteString("\n\t")
|
||||
buffer.WriteString("Queries regexps: ")
|
||||
buffer.WriteString(strings.Join(queriesRegexps, ","))
|
||||
}
|
||||
methods, err := route.GetMethods()
|
||||
if err == nil {
|
||||
buffer.WriteString("\n\t")
|
||||
buffer.WriteString("Methods: ")
|
||||
buffer.WriteString(strings.Join(methods, ","))
|
||||
}
|
||||
|
||||
if len := buffer.Len(); len != 0 {
|
||||
|
||||
log.Println(buffer.String())
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
package marshaling
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"go_project/pkg/behaivor"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// NOTE: Not used in this project
|
||||
func MustUnmarshalBody(r *http.Request, x interface{}) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
behaivor.Anxiety("Error reading the request body", err)
|
||||
err = json.Unmarshal([]byte(body), x)
|
||||
behaivor.Anxiety("Error unmarshaling the request body", err)
|
||||
}
|
||||
Reference in New Issue
Block a user