mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Help needed: vendor files for Prometheus support
These are the vendor files needed for Prometheus support. I have not been able to figure out how to do this properly with gopkg.
This commit is contained in:
committed by
Zlatko Čalušić
parent
ca0e09261f
commit
4cd82b6802
24
vendor/github.com/miolini/datacounter/.gitignore
generated
vendored
Normal file
24
vendor/github.com/miolini/datacounter/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
23
vendor/github.com/miolini/datacounter/.travis.yml
generated
vendored
Normal file
23
vendor/github.com/miolini/datacounter/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
language: go
|
||||
|
||||
# The feature/go15 branch uses new features in go15. Only testing this branch
|
||||
# against tip which has the features.
|
||||
go:
|
||||
- 1.6
|
||||
- tip
|
||||
|
||||
# Setting sudo access to false will let Travis CI use containers rather than
|
||||
# VMs to run the tests. For more details see:
|
||||
# - http://docs.travis-ci.com/user/workers/container-based-infrastructure/
|
||||
# - http://docs.travis-ci.com/user/workers/standard-infrastructure/
|
||||
sudo: false
|
||||
|
||||
install:
|
||||
|
||||
# The default script is go test -v ./... which will test everything
|
||||
# in the vendor directory. We don't need to test all dependent packages.
|
||||
# Only testing this project.
|
||||
script:
|
||||
- GO15VENDOREXPERIMENT=1 go test -v .
|
||||
|
||||
notifications:
|
||||
22
vendor/github.com/miolini/datacounter/LICENSE
generated
vendored
Normal file
22
vendor/github.com/miolini/datacounter/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Artem Andreenko <mio@volmy.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
41
vendor/github.com/miolini/datacounter/README.md
generated
vendored
Normal file
41
vendor/github.com/miolini/datacounter/README.md
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# datacounter
|
||||
Golang counters for readers/writers
|
||||
|
||||
[](https://travis-ci.org/miolini/datacounter) [](http://godoc.org/github.com/miolini/datacounter) [](http://goreportcard.com/report/miolini/datacounter)
|
||||
|
||||
## Examples
|
||||
### ReaderCounter
|
||||
```go
|
||||
buf := bytes.Buffer{}
|
||||
buf.Write(data)
|
||||
counter := datacounter.NewReaderCounter(&buf)
|
||||
io.Copy(ioutil.Discard, counter)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}`
|
||||
```
|
||||
### WriterCounter
|
||||
```go
|
||||
buf := bytes.Buffer{}
|
||||
counter := datacounter.NewWriterCounter(&buf)
|
||||
counter.Write(data)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}
|
||||
```
|
||||
### http.ResponseWriter Counter
|
||||
```go
|
||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(data)
|
||||
}
|
||||
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
counter := datacounter.NewResponseWriterCounter(w)
|
||||
handler(counter, req)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}
|
||||
```
|
||||
31
vendor/github.com/miolini/datacounter/reader.go
generated
vendored
Normal file
31
vendor/github.com/miolini/datacounter/reader.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// ReaderCounter is counter for io.Reader
|
||||
type ReaderCounter struct {
|
||||
io.Reader
|
||||
count uint64
|
||||
reader io.Reader
|
||||
}
|
||||
|
||||
// NewReaderCounter function for create new ReaderCounter
|
||||
func NewReaderCounter(r io.Reader) *ReaderCounter {
|
||||
return &ReaderCounter{
|
||||
reader: r,
|
||||
}
|
||||
}
|
||||
|
||||
func (counter *ReaderCounter) Read(buf []byte) (int, error) {
|
||||
n, err := counter.reader.Read(buf)
|
||||
atomic.AddUint64(&counter.count, uint64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Count function return counted bytes
|
||||
func (counter *ReaderCounter) Count() uint64 {
|
||||
return atomic.LoadUint64(&counter.count)
|
||||
}
|
||||
21
vendor/github.com/miolini/datacounter/reader_test.go
generated
vendored
Normal file
21
vendor/github.com/miolini/datacounter/reader_test.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var data = []byte("Hello, World!")
|
||||
var dataLen = uint64(len(data))
|
||||
|
||||
func TestReaderCounter(t *testing.T) {
|
||||
buf := bytes.Buffer{}
|
||||
buf.Write(data)
|
||||
counter := NewReaderCounter(&buf)
|
||||
io.Copy(ioutil.Discard, counter)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}
|
||||
}
|
||||
45
vendor/github.com/miolini/datacounter/response_writer.go
generated
vendored
Normal file
45
vendor/github.com/miolini/datacounter/response_writer.go
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// ResponseWriterCounter is counter for http.ResponseWriter
|
||||
type ResponseWriterCounter struct {
|
||||
http.ResponseWriter
|
||||
count uint64
|
||||
writer http.ResponseWriter
|
||||
}
|
||||
|
||||
// NewResponseWriterCounter function create new ResponseWriterCounter
|
||||
func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
|
||||
return &ResponseWriterCounter{
|
||||
writer: rw,
|
||||
}
|
||||
}
|
||||
|
||||
func (counter *ResponseWriterCounter) Write(buf []byte) (int, error) {
|
||||
n, err := counter.writer.Write(buf)
|
||||
atomic.AddUint64(&counter.count, uint64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
func (counter *ResponseWriterCounter) Header() http.Header {
|
||||
return counter.writer.Header()
|
||||
}
|
||||
|
||||
func (counter *ResponseWriterCounter) WriteHeader(statusCode int) {
|
||||
counter.writer.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
func (counter *ResponseWriterCounter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
return counter.writer.(http.Hijacker).Hijack()
|
||||
}
|
||||
|
||||
// Count function return counted bytes
|
||||
func (counter *ResponseWriterCounter) Count() uint64 {
|
||||
return atomic.LoadUint64(&counter.count)
|
||||
}
|
||||
23
vendor/github.com/miolini/datacounter/response_writer_test.go
generated
vendored
Normal file
23
vendor/github.com/miolini/datacounter/response_writer_test.go
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResponseWriterCounter(t *testing.T) {
|
||||
handler := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write(data)
|
||||
}
|
||||
req, err := http.NewRequest("GET", "http://example.com/foo", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
counter := NewResponseWriterCounter(w)
|
||||
handler(counter, req)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/miolini/datacounter/writer.go
generated
vendored
Normal file
31
vendor/github.com/miolini/datacounter/writer.go
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// WriterCounter is counter for io.Writer
|
||||
type WriterCounter struct {
|
||||
io.Writer
|
||||
count uint64
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
// NewWriterCounter function create new WriterCounter
|
||||
func NewWriterCounter(w io.Writer) *WriterCounter {
|
||||
return &WriterCounter{
|
||||
writer: w,
|
||||
}
|
||||
}
|
||||
|
||||
func (counter *WriterCounter) Write(buf []byte) (int, error) {
|
||||
n, err := counter.writer.Write(buf)
|
||||
atomic.AddUint64(&counter.count, uint64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Count function return counted bytes
|
||||
func (counter *WriterCounter) Count() uint64 {
|
||||
return atomic.LoadUint64(&counter.count)
|
||||
}
|
||||
15
vendor/github.com/miolini/datacounter/writer_test.go
generated
vendored
Normal file
15
vendor/github.com/miolini/datacounter/writer_test.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
package datacounter
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriterCounter(t *testing.T) {
|
||||
buf := bytes.Buffer{}
|
||||
counter := NewWriterCounter(&buf)
|
||||
counter.Write(data)
|
||||
if counter.Count() != dataLen {
|
||||
t.Fatalf("count mismatch len of test data: %d != %d", counter.Count(), len(data))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user