-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up root directory to conform to standard go spec. (#35)
- There's no need to make separate packages for the zap internals, as it would be just a single file + test per package. - We have to update the build commands to specify the cmd dir.
- Loading branch information
Showing
11 changed files
with
132 additions
and
113 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
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
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,35 @@ | ||
package zap | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/Jeffail/gabs/v2" | ||
) | ||
|
||
type Context struct { | ||
// Json container with path configs | ||
Config *gabs.Container | ||
|
||
// Enables safe hot reloading of Config. | ||
ConfigMtx sync.Mutex | ||
} | ||
|
||
type CtxWrapper struct { | ||
*Context | ||
H func(*Context, http.ResponseWriter, *http.Request) (int, error) | ||
} | ||
|
||
func (cw CtxWrapper) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
status, err := cw.H(cw.Context, w, r) // this runs the actual handler, defined in struct. | ||
if err != nil { | ||
switch status { | ||
case http.StatusInternalServerError: | ||
http.Error(w, fmt.Sprintf("HTTP %d: %q", status, err), status) | ||
// TODO - add bad request? | ||
default: | ||
http.Error(w, err.Error(), status) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package zap | ||
|
||
import ( | ||
"bytes" | ||
|
Oops, something went wrong.