-
Notifications
You must be signed in to change notification settings - Fork 1
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 #8 from ninedraft/add-serve-tls
Add serve tls
- Loading branch information
Showing
8 changed files
with
171 additions
and
58 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 |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
.vscode/ |
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,55 @@ | ||
// Package bufwriter provides a buffered writer gadget. | ||
package bufwriter | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"io" | ||
|
||
"github.com/ninedraft/gemax/internal/multierr" | ||
) | ||
|
||
// Writer is a buffered io.Writer wrapper. | ||
type Writer struct { | ||
isClosed bool | ||
closer io.Closer | ||
*writer | ||
} | ||
|
||
// DefaultBufferSize is used if buffers size is <= 0. | ||
const DefaultBufferSize = 16 << 10 // 16 Kb | ||
|
||
// New creates a new buffered writer. | ||
// If bufSize <= 0, then DefaultBufferSize is used as internal buffer size. | ||
func New(w io.WriteCloser, bufSize int) *Writer { | ||
if bufSize <= 0 { | ||
bufSize = DefaultBufferSize | ||
} | ||
return &Writer{ | ||
closer: w, | ||
writer: bufio.NewWriterSize(w, bufSize), | ||
} | ||
} | ||
|
||
type writer = bufio.Writer | ||
|
||
// Reset buffer and sets new write target. | ||
func (wr *Writer) Reset(w io.WriteCloser) { | ||
wr.isClosed = false | ||
wr.closer = w | ||
wr.writer.Reset(w) | ||
} | ||
|
||
var errAlreadyClosed = errors.New("already closed") | ||
|
||
// Close flushes and closes underlying writer. | ||
func (wr *Writer) Close() error { | ||
if wr.isClosed { | ||
return errAlreadyClosed | ||
} | ||
wr.isClosed = true | ||
return multierr.Combine( | ||
wr.Flush(), | ||
wr.closer.Close(), | ||
) | ||
} |
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,10 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIBWzCCAQCgAwIBAgIBATAKBggqhkjOPQQDBDAQMQ4wDAYDVQQKEwVnZW1heDAe | ||
Fw0yMTAzMTYxNDA0MDJaFw0zMTAzMTQxNDA0MDJaMBAxDjAMBgNVBAoTBWdlbWF4 | ||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEyNzg8+oClgjoilsvQaDfaPtn8lXJ | ||
57mUJzS92B4HrT5MXwS+6RzjzrOaXezk9oWHepsfyfLE7zNyGKzkb663RqNLMEkw | ||
DgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoGCCsGAQUFBwMBMAwGA1UdEwEB/wQC | ||
MAAwFAYDVR0RBA0wC4IJbG9jYWxob3N0MAoGCCqGSM49BAMEA0kAMEYCIQDHPwlp | ||
MX2OA3yrqT5V6HlXtDlwy75WAqi50tXJAnJPygIhAICFq1OKKTxsWFlCQwWwss+/ | ||
F+EomW3F92wTWhxpyELh | ||
-----END CERTIFICATE----- |
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,5 @@ | ||
-----BEGIN EC PRIVATE KEY----- | ||
MHcCAQEEIDLP4kH0EwzuMHcXdvtuV4IXFyBbPH6leoicqS5gLKO3oAoGCCqGSM49 | ||
AwEHoUQDQgAEyNzg8+oClgjoilsvQaDfaPtn8lXJ57mUJzS92B4HrT5MXwS+6Rzj | ||
zrOaXezk9oWHepsfyfLE7zNyGKzkb663Rg== | ||
-----END EC PRIVATE KEY----- |