-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0d996b
commit 1b9cb17
Showing
14 changed files
with
781 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vscode | ||
.idea | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
Configuration: | ||
info: | ||
name: "web-serve" # Name of the server as a service | ||
short: "The Production Build Server" # Short info about the server service name | ||
|
||
server: | ||
port: 8080 # Port on which server is running | ||
mode: "RELEASE" # Another option DEBUG | ||
|
||
failsafe: true # If failsafe is set for Single Page Application while hitting virtual routes index.html will be rendered alongside | ||
|
||
htmlblacklist: # list of routes where html will not be rendered - a 404 page will be rendered | ||
- /ping # health check | ||
- /admin | ||
|
||
blacklist: # list of routes where instead of an 404 HTML an 404 JSON will be returned | ||
- /custom | ||
|
||
page404: html/404.html # Path where 404.html can be customised for certain routes if not handled by the SPA | ||
|
||
timeout: # in seconds | ||
read: 1 | ||
write: 1 | ||
idle: 120 | ||
|
||
logging: # Each request is going to be logged | ||
logdir: . | ||
logfile: traffic.log | ||
stdout: true # Also log to Stdout true/false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Package core | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"time" | ||
) | ||
|
||
func logFilter() gin.HandlerFunc { | ||
return gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string { | ||
return fmt.Sprintf("IP %s - [%s] \"%s PATH: %s \t\t%s %d LATENCY: %s\" %s\" %s\" BODYSIZE: %d\n", | ||
param.ClientIP, | ||
param.TimeStamp.Format(time.RFC1123), | ||
param.Method, | ||
param.Path, | ||
param.Request.Proto, | ||
param.StatusCode, | ||
param.Latency, | ||
param.Request.UserAgent(), | ||
param.ErrorMessage, | ||
param.BodySize, | ||
) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Package core | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package core | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/spf13/viper" | ||
"os" | ||
) | ||
|
||
type Info struct { | ||
Name string | ||
Short string | ||
} | ||
|
||
type Server struct { | ||
Port int | ||
Mode string | ||
Failsafe bool | ||
HtmlBlackList []string | ||
Blacklist []string | ||
Page404 string | ||
Timeout struct { | ||
Read int | ||
Write int | ||
IDLE int | ||
} | ||
} | ||
type Logging struct { | ||
Logdir string | ||
Logfile string | ||
Stdout bool | ||
} | ||
|
||
type Config struct { | ||
Configuration struct { | ||
Info Info | ||
Server Server | ||
Logging Logging | ||
} | ||
} | ||
|
||
func (c *Config) Parse(conf string) error { | ||
viper.SetConfigType("yml") | ||
err := viper.ReadConfig(bytes.NewBuffer([]byte(conf))) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
err = viper.Unmarshal(c) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse configuration YAML: %s\n", err) | ||
} | ||
if c.Configuration.Logging.Logdir == "." { | ||
dir, err := os.Getwd() | ||
if err != nil { | ||
return fmt.Errorf("use path instead of '.' for logdir: %s", err) | ||
} | ||
c.Configuration.Logging.Logdir = dir | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.