-
Notifications
You must be signed in to change notification settings - Fork 4
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 #39 from pior/logs
Refactor logging
- Loading branch information
Showing
8 changed files
with
76 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,41 @@ | ||
package runnable_test | ||
package runnable | ||
|
||
import ( | ||
"context" | ||
stdlog "log" | ||
"net/http" | ||
"os" | ||
"time" | ||
|
||
"github.com/pior/runnable" | ||
) | ||
|
||
func ExampleHTTPServer() { | ||
runnable.SetLogger(stdlog.New(os.Stdout, "", 0)) | ||
ctx, cancel := initializeForExample() | ||
defer cancel() | ||
|
||
server := &http.Server{ | ||
Addr: "127.0.0.1:8080", | ||
Handler: http.NotFoundHandler(), | ||
} | ||
|
||
r := runnable.HTTPServer(server) | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*100) | ||
defer cancel() | ||
r := HTTPServer(server) | ||
|
||
_ = r.Run(ctx) | ||
|
||
// Output: | ||
// http_server: listening on 127.0.0.1:8080 | ||
// http_server: shutdown | ||
// httpserver: listening on 127.0.0.1:8080 | ||
// httpserver: shutdown | ||
} | ||
|
||
func ExampleHTTPServer_error() { | ||
runnable.SetLogger(stdlog.New(os.Stdout, "", 0)) | ||
ctx, cancel := initializeForExample() | ||
defer cancel() | ||
|
||
server := &http.Server{ | ||
Addr: "INVALID", | ||
Handler: http.NotFoundHandler(), | ||
} | ||
|
||
r := runnable.HTTPServer(server) | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithTimeout(ctx, time.Millisecond*1000) | ||
defer cancel() | ||
r := HTTPServer(server) | ||
|
||
_ = r.Run(ctx) | ||
|
||
// Output: | ||
// http_server: listening on INVALID | ||
// http_server: shutdown (err: listen tcp: address INVALID: missing port in address) | ||
// httpserver: listening on INVALID | ||
// httpserver: shutdown (err: listen tcp: address INVALID: missing port in address) | ||
} |
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