-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DamienFontaine/develop
Develop
- Loading branch information
Showing
328 changed files
with
140,907 additions
and
356 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 |
---|---|---|
@@ -1 +1,4 @@ | ||
*.coverprofile | ||
testdata/logs/*.log | ||
testdata/lunarc.log | ||
testdata/access.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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,69 @@ | ||
// Copyright (c) - Damien Fontaine <damien.fontaine@lineolia.net> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/> | ||
|
||
package lunarc | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
|
||
"github.com/DamienFontaine/lunarc/config" | ||
|
||
"github.com/Sirupsen/logrus" | ||
) | ||
|
||
const aFilename = "access.log" | ||
|
||
// LoggingServeMux logs HTTP requests | ||
type LoggingServeMux struct { | ||
serveMux *http.ServeMux | ||
conf config.Server | ||
} | ||
|
||
// NewLoggingServeMux allocates and returns a new LoggingServeMux | ||
func NewLoggingServeMux(conf config.Server) *LoggingServeMux { | ||
serveMux := http.NewServeMux() | ||
return &LoggingServeMux{serveMux, conf} | ||
} | ||
|
||
// Handler sastisfy interface | ||
func (mux *LoggingServeMux) Handler(r *http.Request) (h http.Handler, pattern string) { | ||
return mux.serveMux.Handler(r) | ||
} | ||
|
||
//ServeHTTP | ||
func (mux *LoggingServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
mux.serveMux.ServeHTTP(w, r) | ||
} | ||
|
||
//Handle register handler | ||
func (mux *LoggingServeMux) Handle(pattern string, handler http.Handler) { | ||
|
||
var log = logrus.New() | ||
|
||
logFile, err := os.OpenFile(mux.conf.Log.File+aFilename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666) | ||
if err != nil { | ||
log.Out = os.Stderr | ||
log.Warningf("Can't open logfile: %v", err) | ||
} else { | ||
log.Out = logFile | ||
} | ||
mux.serveMux.Handle(pattern, Logging(handler, log)) | ||
} | ||
|
||
// HandleFunc registers the handler function for the given pattern. | ||
func (mux *LoggingServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { | ||
mux.serveMux.Handle(pattern, http.HandlerFunc(handler)) | ||
} |
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
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,52 @@ | ||
// Copyright (c) - Damien Fontaine <damien.fontaine@lineolia.net> | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/> | ||
|
||
package lunarc | ||
|
||
import "net/http" | ||
|
||
// StatusResponseWriter returns status code | ||
type StatusResponseWriter struct { | ||
http.ResponseWriter | ||
status int | ||
length int | ||
} | ||
|
||
// Status return status code | ||
func (w *StatusResponseWriter) Status() int { | ||
return w.status | ||
} | ||
|
||
// Length return response size | ||
func (w *StatusResponseWriter) Length() int { | ||
return w.length | ||
} | ||
|
||
// Header Satisfy the http.ResponseWriter interface | ||
func (w *StatusResponseWriter) Header() http.Header { | ||
return w.ResponseWriter.Header() | ||
} | ||
|
||
// Write Satisfy the http.ResponseWriter interface | ||
func (w *StatusResponseWriter) Write(data []byte) (int, error) { | ||
w.length = len(data) | ||
return w.ResponseWriter.Write(data) | ||
} | ||
|
||
// WriteHeader writes status code | ||
func (w *StatusResponseWriter) WriteHeader(statusCode int) { | ||
w.status = statusCode | ||
w.ResponseWriter.WriteHeader(statusCode) | ||
} |
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.