Compare commits
218
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4919af95a | ||
|
|
58104a50ec | ||
|
|
99b18d4b5d | ||
|
|
430fc530f2 | ||
|
|
0945466653 | ||
|
|
91ac7abf08 | ||
|
|
8161f48c15 | ||
|
|
d11230aaf8 | ||
|
|
8fd87dfc31 | ||
|
|
4056c44c2e | ||
|
|
dd451eb72b | ||
|
|
a553e18d3b | ||
|
|
3e18b74da0 | ||
|
|
55dceeaa4e | ||
|
|
a1177c17d3 | ||
|
|
2b155597bf | ||
|
|
87bf89a109 | ||
|
|
931d786c52 | ||
|
|
6516df1418 | ||
|
|
3027fb9b98 | ||
|
|
ed51ece75c | ||
|
|
e00cdd0237 | ||
|
|
6bc878d657 | ||
|
|
be64130ae1 | ||
|
|
419e7c88a3 | ||
|
|
988178df50 | ||
|
|
a365d63d16 | ||
|
|
bd452c421f | ||
|
|
4c3372992c | ||
|
|
3c99b84721 | ||
|
|
d7e84c6b97 | ||
|
|
4580a95b74 | ||
|
|
29773829af | ||
|
|
ef1b43ac62 | ||
|
|
39e5821760 | ||
|
|
cb68cb004e | ||
|
|
eb6bb93500 | ||
|
|
d0df93ebac | ||
|
|
8c41d8ccd9 | ||
|
|
e9753ffdc7 | ||
|
|
69e03da94a | ||
|
|
b3f7657c1b | ||
|
|
29574578c1 | ||
|
|
73382bb021 | ||
|
|
69e2f6231c | ||
|
|
fb88808c97 | ||
|
|
a16797cc53 | ||
|
|
b14fb6c18b | ||
|
|
8db975b532 | ||
|
|
fcade74753 | ||
|
|
f1d8bc0ffc | ||
|
|
9d8b9330f9 | ||
|
|
3ae040d677 | ||
|
|
07d2d00b0d | ||
|
|
86d0678274 | ||
|
|
bdf6240ed8 | ||
|
|
e8b93e3bb1 | ||
|
|
9a9be92d27 | ||
|
|
414be62d61 | ||
|
|
21017a38a7 | ||
|
|
1a30fb743b | ||
|
|
db8aa21b35 | ||
|
|
c4772e61c5 | ||
|
|
9541d765a9 | ||
|
|
f9717328bc | ||
|
|
1835deb2c9 | ||
|
|
dc6b15a372 | ||
|
|
635bf931c8 | ||
|
|
d12e431b40 | ||
|
|
8f8b2e605b | ||
|
|
9b6fea461c | ||
|
|
a391c83a2f | ||
|
|
06764c3d00 | ||
|
|
b68c49ac2f | ||
|
|
96ace4b850 | ||
|
|
6782b19c3d | ||
|
|
bcadcd1eca | ||
|
|
ef1b10b601 | ||
|
|
aec378bb36 | ||
|
|
fa9bab156a | ||
|
|
de5b32b1b5 | ||
|
|
dd2171172d | ||
|
|
1155ea6b9d | ||
|
|
6918a2436a | ||
|
|
7e524c6b08 | ||
|
|
9c278d131d | ||
|
|
b1c090e28d | ||
|
|
b03e0a7db8 | ||
|
|
33071ff6c1 | ||
|
|
30a9a39248 | ||
|
|
49c9531404 | ||
|
|
c68c7e05fe | ||
|
|
534831e6e5 | ||
|
|
deab868c53 | ||
|
|
d5102a9cf6 | ||
|
|
ac75979453 | ||
|
|
712e346bd2 | ||
|
|
85e34cb335 | ||
|
|
c36c67961f | ||
|
|
025c715ab4 | ||
|
|
af728f12d9 | ||
|
|
1f1848a408 | ||
|
|
d032c842d5 | ||
|
|
d6f5199acd | ||
|
|
28aad86e4a | ||
|
|
c5c634e477 | ||
|
|
a8c339e5b4 | ||
|
|
fd916d9eae | ||
|
|
2d45f059ec | ||
|
|
e5850035dd | ||
|
|
0cfc8e230c | ||
|
|
f3a1fbdd53 | ||
|
|
ecbd404da0 | ||
|
|
2768cdd312 | ||
|
|
564595cfc3 | ||
|
|
3a3377d0e5 | ||
|
|
38861421f8 | ||
|
|
a7bb3cf336 | ||
|
|
8fa28d3d65 | ||
|
|
f8a231286a | ||
|
|
ea5b70e8fc | ||
|
|
26b0c7356d | ||
|
|
7558397877 | ||
|
|
fb7d045753 | ||
|
|
4d17553a23 | ||
|
|
40633c949e | ||
|
|
a17fa3ad5f | ||
|
|
560858ba0a | ||
|
|
ada0ce0484 | ||
|
|
461ae6a16b | ||
|
|
31456e7bae | ||
|
|
060970b7c0 | ||
|
|
0f894aaecc | ||
|
|
8367901104 | ||
|
|
7e445e0cf8 | ||
|
|
f5de4e96c3 | ||
|
|
6226c2690d | ||
|
|
3335233566 | ||
|
|
faac895509 | ||
|
|
bc9886b3e8 | ||
|
|
963177cd4c | ||
|
|
6d2f69a36f | ||
|
|
b444d284c6 | ||
|
|
f853f2a00b | ||
|
|
a8afd1621e | ||
|
|
88aad289cf | ||
|
|
de1476becf | ||
|
|
6ae869bdb3 | ||
|
|
818b00190d | ||
|
|
630260d0b1 | ||
|
|
15a137c502 | ||
|
|
438be5767a | ||
|
|
6c7f59bfb8 | ||
|
|
7220ec8943 | ||
|
|
3615ab5e55 | ||
|
|
7ba00dffcc | ||
|
|
76b73ef0c7 | ||
|
|
5424746066 | ||
|
|
b6b411847a | ||
|
|
6bda111ffa | ||
|
|
77ea5aa522 | ||
|
|
abb34bf2dc | ||
|
|
c3aeba7e17 | ||
|
|
8e52397bb4 | ||
|
|
ebc3b6a55d | ||
|
|
7b0a5ae028 | ||
|
|
13ef7571b2 | ||
|
|
b63ee94973 | ||
|
|
2ae66ad3f7 | ||
|
|
52702e2226 | ||
|
|
f827da4c61 | ||
|
|
3d2986a85c | ||
|
|
1d3e6c524b | ||
|
|
5f847fb035 | ||
|
|
6f0d34f863 | ||
|
|
41b4a3684a | ||
|
|
38d493fdd1 | ||
|
|
d33ac919d1 | ||
|
|
ec0eec8ac4 | ||
|
|
2437a06505 | ||
|
|
e90b6dfcc7 | ||
|
|
c0a12af3ae | ||
|
|
d701bab7f6 | ||
|
|
c54836bca0 | ||
|
|
322c658307 | ||
|
|
16f251b7f3 | ||
|
|
ce30f66823 | ||
|
|
3d72de1cec | ||
|
|
bad2d869f5 | ||
|
|
846f1afaab | ||
|
|
414540ec6d | ||
|
|
9159c7602d | ||
|
|
211c2884c2 | ||
|
|
74be347b9e | ||
|
|
50996a6b0d | ||
|
|
e29b47a047 | ||
|
|
38325c6d44 | ||
|
|
c84b36d76d | ||
|
|
95c75ed957 | ||
|
|
ccd1b2b84d | ||
|
|
dac2dbda61 | ||
|
|
2e58228e91 | ||
|
|
185433f2fd | ||
|
|
40f9c3f961 | ||
|
|
dd814b834b | ||
|
|
cdaf3ac682 | ||
|
|
6d169425d1 | ||
|
|
f53da5c3e5 | ||
|
|
d89334f9eb | ||
|
|
2fcc2f106e | ||
|
|
4cff2dd233 | ||
|
|
37a8c4cae1 | ||
|
|
8aaa786512 | ||
|
|
1f23a260ae | ||
|
|
e02762ab6c | ||
|
|
9a629bb545 | ||
|
|
c62c175d8b | ||
|
|
eb8f72f0d8 |
No files matched your search
+16
-5
@@ -2,17 +2,28 @@ os: linux
|
||||
dist: xenial
|
||||
language: go
|
||||
go:
|
||||
- 1.11.x
|
||||
- 1.15.x
|
||||
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
||||
global:
|
||||
- GO111MODULE=on
|
||||
#GITHUB_TOKEN
|
||||
- secure: "P4YMfllsq/guf5swmBl80IHGvNfUM+5X2b+0LvQQxGJpY9TD6d+PW6U1C90HIT0CDk6UZbtlHyGN+oo+shsWnwMIaM4qmbGdRgtG4TZolXY1QtYQZFW9fTWeHM0wnJeXLV8V4vpTRHnkLrvT8PctbGp5pVOEtcV4y3sEnMP1rkxnMPeHtrDbTlpBmBYEziByEpbg3pe3CE9xVaDD9DqgW7VOOZnQQl7exTtjsIeJYI7OYvdidf/04p632/8WZP2EJbmA2HunfTydWtcD51lCF8V3IvhKKqH4/7sNOKfmUwTDyhLltk9eDcFsYR/FYsy8njH4QDBBrKo/bPq3jzgKF9BY7g28/jMTDY4vDY0Na+4a3+7sDqwdsZ+eiZrgWYUbZ4MwYtpUtcvp8gUz7Avs3v7BBgYsYpgLEW47bT6uNLGO+SdfSwBCYuxT5P0IGCv6wkgYcYgfqVafk+9FiwJlayP2j3wPOdauiYh4WnYX1Rt0zNvaiP5iBhkXwIv3VvUcI1Yu9k0eLDibzZlpR8fkGw3USl+omdjCvXDfJQW1ghMONTm0d7VPG84P/MRhJ+thoh1UwMaT3S0sdPznRnNL6XDntCRT1CZW4l0jfyCPDBW2qw8dWunULYsQZTPWnv4s+BuRRDsfGjyamH5b8evh0TOF+XNOFewmNvflWBNG2y0="
|
||||
install: true
|
||||
|
||||
script:
|
||||
# Fail if a .go file hasn't been formatted with gofmt
|
||||
- test -z $(gofmt -s -l $(find . -iname '*.go' -type f | grep -v /vendor/ ))
|
||||
- test -z $(gofmt -s -l $(find . -iname '*.go' -type f))
|
||||
- make
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
email: false
|
||||
|
||||
deploy:
|
||||
provider: script
|
||||
skip_cleanup: true
|
||||
script: ./scripts/deploy.sh
|
||||
file: bin/lbry
|
||||
on:
|
||||
repo: lbryio/lbry.go
|
||||
tags: true
|
||||
@@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016-2018 LBRY Inc
|
||||
Copyright (c) 2016-2020 LBRY Inc
|
||||
|
||||
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:
|
||||
|
||||
|
||||
@@ -1,765 +0,0 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// source: blobex.proto
|
||||
|
||||
package blobex
|
||||
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/golang/protobuf/proto"
|
||||
math "math"
|
||||
)
|
||||
|
||||
import (
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = proto.Marshal
|
||||
var _ = fmt.Errorf
|
||||
var _ = math.Inf
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the proto package it is being compiled against.
|
||||
// A compilation error at this line likely means your copy of the
|
||||
// proto package needs to be updated.
|
||||
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||
|
||||
type Error struct {
|
||||
// should we enum the error codes?
|
||||
Code uint32 `protobuf:"varint,1,opt,name=code,proto3" json:"code,omitempty"`
|
||||
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *Error) Reset() { *m = Error{} }
|
||||
func (m *Error) String() string { return proto.CompactTextString(m) }
|
||||
func (*Error) ProtoMessage() {}
|
||||
func (*Error) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{0}
|
||||
}
|
||||
|
||||
func (m *Error) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_Error.Unmarshal(m, b)
|
||||
}
|
||||
func (m *Error) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_Error.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *Error) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_Error.Merge(m, src)
|
||||
}
|
||||
func (m *Error) XXX_Size() int {
|
||||
return xxx_messageInfo_Error.Size(m)
|
||||
}
|
||||
func (m *Error) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_Error.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_Error proto.InternalMessageInfo
|
||||
|
||||
func (m *Error) GetCode() uint32 {
|
||||
if m != nil {
|
||||
return m.Code
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *Error) GetMessage() string {
|
||||
if m != nil {
|
||||
return m.Message
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// how much does the host charge per kb at the moment
|
||||
type PriceCheckRequest struct {
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *PriceCheckRequest) Reset() { *m = PriceCheckRequest{} }
|
||||
func (m *PriceCheckRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*PriceCheckRequest) ProtoMessage() {}
|
||||
func (*PriceCheckRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{1}
|
||||
}
|
||||
|
||||
func (m *PriceCheckRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_PriceCheckRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *PriceCheckRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_PriceCheckRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *PriceCheckRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PriceCheckRequest.Merge(m, src)
|
||||
}
|
||||
func (m *PriceCheckRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_PriceCheckRequest.Size(m)
|
||||
}
|
||||
func (m *PriceCheckRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PriceCheckRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PriceCheckRequest proto.InternalMessageInfo
|
||||
|
||||
type PriceCheckResponse struct {
|
||||
Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
|
||||
DeweysPerKB uint64 `protobuf:"varint,2,opt,name=deweysPerKB,proto3" json:"deweysPerKB,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *PriceCheckResponse) Reset() { *m = PriceCheckResponse{} }
|
||||
func (m *PriceCheckResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*PriceCheckResponse) ProtoMessage() {}
|
||||
func (*PriceCheckResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{2}
|
||||
}
|
||||
|
||||
func (m *PriceCheckResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_PriceCheckResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *PriceCheckResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_PriceCheckResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *PriceCheckResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_PriceCheckResponse.Merge(m, src)
|
||||
}
|
||||
func (m *PriceCheckResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_PriceCheckResponse.Size(m)
|
||||
}
|
||||
func (m *PriceCheckResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_PriceCheckResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_PriceCheckResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *PriceCheckResponse) GetError() *Error {
|
||||
if m != nil {
|
||||
return m.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *PriceCheckResponse) GetDeweysPerKB() uint64 {
|
||||
if m != nil {
|
||||
return m.DeweysPerKB
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// are any of the hashs available for download, or are any of the hashes desired for upload
|
||||
// NOTE: if any hashes are stream hashes, and the server has the manifest but not all the content
|
||||
// blobs, the server may reply that it needs extra blobs that were not in the original request
|
||||
type HashesRequest struct {
|
||||
Hashes []string `protobuf:"bytes,1,rep,name=hashes,proto3" json:"hashes,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *HashesRequest) Reset() { *m = HashesRequest{} }
|
||||
func (m *HashesRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*HashesRequest) ProtoMessage() {}
|
||||
func (*HashesRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{3}
|
||||
}
|
||||
|
||||
func (m *HashesRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_HashesRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *HashesRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_HashesRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *HashesRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_HashesRequest.Merge(m, src)
|
||||
}
|
||||
func (m *HashesRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_HashesRequest.Size(m)
|
||||
}
|
||||
func (m *HashesRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_HashesRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_HashesRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *HashesRequest) GetHashes() []string {
|
||||
if m != nil {
|
||||
return m.Hashes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type HashesResponse struct {
|
||||
Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
|
||||
Hashes map[string]bool `protobuf:"bytes,2,rep,name=hashes,proto3" json:"hashes,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *HashesResponse) Reset() { *m = HashesResponse{} }
|
||||
func (m *HashesResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*HashesResponse) ProtoMessage() {}
|
||||
func (*HashesResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{4}
|
||||
}
|
||||
|
||||
func (m *HashesResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_HashesResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *HashesResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_HashesResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *HashesResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_HashesResponse.Merge(m, src)
|
||||
}
|
||||
func (m *HashesResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_HashesResponse.Size(m)
|
||||
}
|
||||
func (m *HashesResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_HashesResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_HashesResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *HashesResponse) GetError() *Error {
|
||||
if m != nil {
|
||||
return m.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *HashesResponse) GetHashes() map[string]bool {
|
||||
if m != nil {
|
||||
return m.Hashes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// download the hash
|
||||
type DownloadRequest struct {
|
||||
Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *DownloadRequest) Reset() { *m = DownloadRequest{} }
|
||||
func (m *DownloadRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*DownloadRequest) ProtoMessage() {}
|
||||
func (*DownloadRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{5}
|
||||
}
|
||||
|
||||
func (m *DownloadRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_DownloadRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *DownloadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_DownloadRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *DownloadRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_DownloadRequest.Merge(m, src)
|
||||
}
|
||||
func (m *DownloadRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_DownloadRequest.Size(m)
|
||||
}
|
||||
func (m *DownloadRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_DownloadRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_DownloadRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *DownloadRequest) GetHash() string {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type DownloadResponse struct {
|
||||
Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
|
||||
Hash string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
Blob []byte `protobuf:"bytes,3,opt,name=blob,proto3" json:"blob,omitempty"`
|
||||
Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"`
|
||||
Price uint64 `protobuf:"varint,5,opt,name=price,proto3" json:"price,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) Reset() { *m = DownloadResponse{} }
|
||||
func (m *DownloadResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*DownloadResponse) ProtoMessage() {}
|
||||
func (*DownloadResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{6}
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_DownloadResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *DownloadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_DownloadResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *DownloadResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_DownloadResponse.Merge(m, src)
|
||||
}
|
||||
func (m *DownloadResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_DownloadResponse.Size(m)
|
||||
}
|
||||
func (m *DownloadResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_DownloadResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_DownloadResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *DownloadResponse) GetError() *Error {
|
||||
if m != nil {
|
||||
return m.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) GetHash() string {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) GetBlob() []byte {
|
||||
if m != nil {
|
||||
return m.Blob
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) GetAddress() string {
|
||||
if m != nil {
|
||||
return m.Address
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *DownloadResponse) GetPrice() uint64 {
|
||||
if m != nil {
|
||||
return m.Price
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// upload the hash
|
||||
type UploadRequest struct {
|
||||
Hash string `protobuf:"bytes,1,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
Blob []byte `protobuf:"bytes,2,opt,name=blob,proto3" json:"blob,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *UploadRequest) Reset() { *m = UploadRequest{} }
|
||||
func (m *UploadRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*UploadRequest) ProtoMessage() {}
|
||||
func (*UploadRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{7}
|
||||
}
|
||||
|
||||
func (m *UploadRequest) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_UploadRequest.Unmarshal(m, b)
|
||||
}
|
||||
func (m *UploadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_UploadRequest.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *UploadRequest) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_UploadRequest.Merge(m, src)
|
||||
}
|
||||
func (m *UploadRequest) XXX_Size() int {
|
||||
return xxx_messageInfo_UploadRequest.Size(m)
|
||||
}
|
||||
func (m *UploadRequest) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_UploadRequest.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_UploadRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *UploadRequest) GetHash() string {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *UploadRequest) GetBlob() []byte {
|
||||
if m != nil {
|
||||
return m.Blob
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UploadResponse struct {
|
||||
Error *Error `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"`
|
||||
Hash string `protobuf:"bytes,2,opt,name=hash,proto3" json:"hash,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *UploadResponse) Reset() { *m = UploadResponse{} }
|
||||
func (m *UploadResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*UploadResponse) ProtoMessage() {}
|
||||
func (*UploadResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_183aee39e18f30c9, []int{8}
|
||||
}
|
||||
|
||||
func (m *UploadResponse) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_UploadResponse.Unmarshal(m, b)
|
||||
}
|
||||
func (m *UploadResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_UploadResponse.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *UploadResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_UploadResponse.Merge(m, src)
|
||||
}
|
||||
func (m *UploadResponse) XXX_Size() int {
|
||||
return xxx_messageInfo_UploadResponse.Size(m)
|
||||
}
|
||||
func (m *UploadResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_UploadResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_UploadResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *UploadResponse) GetError() *Error {
|
||||
if m != nil {
|
||||
return m.Error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *UploadResponse) GetHash() string {
|
||||
if m != nil {
|
||||
return m.Hash
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Error)(nil), "blobex.Error")
|
||||
proto.RegisterType((*PriceCheckRequest)(nil), "blobex.PriceCheckRequest")
|
||||
proto.RegisterType((*PriceCheckResponse)(nil), "blobex.PriceCheckResponse")
|
||||
proto.RegisterType((*HashesRequest)(nil), "blobex.HashesRequest")
|
||||
proto.RegisterType((*HashesResponse)(nil), "blobex.HashesResponse")
|
||||
proto.RegisterMapType((map[string]bool)(nil), "blobex.HashesResponse.HashesEntry")
|
||||
proto.RegisterType((*DownloadRequest)(nil), "blobex.DownloadRequest")
|
||||
proto.RegisterType((*DownloadResponse)(nil), "blobex.DownloadResponse")
|
||||
proto.RegisterType((*UploadRequest)(nil), "blobex.UploadRequest")
|
||||
proto.RegisterType((*UploadResponse)(nil), "blobex.UploadResponse")
|
||||
}
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
const _ = grpc.SupportPackageIsVersion4
|
||||
|
||||
// BlobExchangeClient is the client API for BlobExchange service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
|
||||
type BlobExchangeClient interface {
|
||||
PriceCheck(ctx context.Context, in *PriceCheckRequest, opts ...grpc.CallOption) (*PriceCheckResponse, error)
|
||||
DownloadCheck(ctx context.Context, in *HashesRequest, opts ...grpc.CallOption) (*HashesResponse, error)
|
||||
Download(ctx context.Context, opts ...grpc.CallOption) (BlobExchange_DownloadClient, error)
|
||||
UploadCheck(ctx context.Context, in *HashesRequest, opts ...grpc.CallOption) (*HashesResponse, error)
|
||||
Upload(ctx context.Context, opts ...grpc.CallOption) (BlobExchange_UploadClient, error)
|
||||
}
|
||||
|
||||
type blobExchangeClient struct {
|
||||
cc *grpc.ClientConn
|
||||
}
|
||||
|
||||
func NewBlobExchangeClient(cc *grpc.ClientConn) BlobExchangeClient {
|
||||
return &blobExchangeClient{cc}
|
||||
}
|
||||
|
||||
func (c *blobExchangeClient) PriceCheck(ctx context.Context, in *PriceCheckRequest, opts ...grpc.CallOption) (*PriceCheckResponse, error) {
|
||||
out := new(PriceCheckResponse)
|
||||
err := c.cc.Invoke(ctx, "/blobex.BlobExchange/PriceCheck", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *blobExchangeClient) DownloadCheck(ctx context.Context, in *HashesRequest, opts ...grpc.CallOption) (*HashesResponse, error) {
|
||||
out := new(HashesResponse)
|
||||
err := c.cc.Invoke(ctx, "/blobex.BlobExchange/DownloadCheck", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *blobExchangeClient) Download(ctx context.Context, opts ...grpc.CallOption) (BlobExchange_DownloadClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_BlobExchange_serviceDesc.Streams[0], "/blobex.BlobExchange/Download", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &blobExchangeDownloadClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type BlobExchange_DownloadClient interface {
|
||||
Send(*DownloadRequest) error
|
||||
Recv() (*DownloadResponse, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type blobExchangeDownloadClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *blobExchangeDownloadClient) Send(m *DownloadRequest) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *blobExchangeDownloadClient) Recv() (*DownloadResponse, error) {
|
||||
m := new(DownloadResponse)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *blobExchangeClient) UploadCheck(ctx context.Context, in *HashesRequest, opts ...grpc.CallOption) (*HashesResponse, error) {
|
||||
out := new(HashesResponse)
|
||||
err := c.cc.Invoke(ctx, "/blobex.BlobExchange/UploadCheck", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *blobExchangeClient) Upload(ctx context.Context, opts ...grpc.CallOption) (BlobExchange_UploadClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, &_BlobExchange_serviceDesc.Streams[1], "/blobex.BlobExchange/Upload", opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &blobExchangeUploadClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type BlobExchange_UploadClient interface {
|
||||
Send(*UploadRequest) error
|
||||
Recv() (*UploadResponse, error)
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
type blobExchangeUploadClient struct {
|
||||
grpc.ClientStream
|
||||
}
|
||||
|
||||
func (x *blobExchangeUploadClient) Send(m *UploadRequest) error {
|
||||
return x.ClientStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *blobExchangeUploadClient) Recv() (*UploadResponse, error) {
|
||||
m := new(UploadResponse)
|
||||
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// BlobExchangeServer is the server API for BlobExchange service.
|
||||
type BlobExchangeServer interface {
|
||||
PriceCheck(context.Context, *PriceCheckRequest) (*PriceCheckResponse, error)
|
||||
DownloadCheck(context.Context, *HashesRequest) (*HashesResponse, error)
|
||||
Download(BlobExchange_DownloadServer) error
|
||||
UploadCheck(context.Context, *HashesRequest) (*HashesResponse, error)
|
||||
Upload(BlobExchange_UploadServer) error
|
||||
}
|
||||
|
||||
func RegisterBlobExchangeServer(s *grpc.Server, srv BlobExchangeServer) {
|
||||
s.RegisterService(&_BlobExchange_serviceDesc, srv)
|
||||
}
|
||||
|
||||
func _BlobExchange_PriceCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PriceCheckRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BlobExchangeServer).PriceCheck(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/blobex.BlobExchange/PriceCheck",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BlobExchangeServer).PriceCheck(ctx, req.(*PriceCheckRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BlobExchange_DownloadCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(HashesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BlobExchangeServer).DownloadCheck(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/blobex.BlobExchange/DownloadCheck",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BlobExchangeServer).DownloadCheck(ctx, req.(*HashesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BlobExchange_Download_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(BlobExchangeServer).Download(&blobExchangeDownloadServer{stream})
|
||||
}
|
||||
|
||||
type BlobExchange_DownloadServer interface {
|
||||
Send(*DownloadResponse) error
|
||||
Recv() (*DownloadRequest, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type blobExchangeDownloadServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *blobExchangeDownloadServer) Send(m *DownloadResponse) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *blobExchangeDownloadServer) Recv() (*DownloadRequest, error) {
|
||||
m := new(DownloadRequest)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func _BlobExchange_UploadCheck_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(HashesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(BlobExchangeServer).UploadCheck(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/blobex.BlobExchange/UploadCheck",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(BlobExchangeServer).UploadCheck(ctx, req.(*HashesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _BlobExchange_Upload_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||
return srv.(BlobExchangeServer).Upload(&blobExchangeUploadServer{stream})
|
||||
}
|
||||
|
||||
type BlobExchange_UploadServer interface {
|
||||
Send(*UploadResponse) error
|
||||
Recv() (*UploadRequest, error)
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
type blobExchangeUploadServer struct {
|
||||
grpc.ServerStream
|
||||
}
|
||||
|
||||
func (x *blobExchangeUploadServer) Send(m *UploadResponse) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (x *blobExchangeUploadServer) Recv() (*UploadRequest, error) {
|
||||
m := new(UploadRequest)
|
||||
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
var _BlobExchange_serviceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "blobex.BlobExchange",
|
||||
HandlerType: (*BlobExchangeServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "PriceCheck",
|
||||
Handler: _BlobExchange_PriceCheck_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DownloadCheck",
|
||||
Handler: _BlobExchange_DownloadCheck_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UploadCheck",
|
||||
Handler: _BlobExchange_UploadCheck_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
StreamName: "Download",
|
||||
Handler: _BlobExchange_Download_Handler,
|
||||
ServerStreams: true,
|
||||
ClientStreams: true,
|
||||
},
|
||||
{
|
||||
StreamName: "Upload",
|
||||
Handler: _BlobExchange_Upload_Handler,
|
||||
ServerStreams: true,
|
||||
ClientStreams: true,
|
||||
},
|
||||
},
|
||||
Metadata: "blobex.proto",
|
||||
}
|
||||
|
||||
func init() { proto.RegisterFile("blobex.proto", fileDescriptor_183aee39e18f30c9) }
|
||||
|
||||
var fileDescriptor_183aee39e18f30c9 = []byte{
|
||||
// 449 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x54, 0xcd, 0x6e, 0x13, 0x31,
|
||||
0x10, 0xae, 0x37, 0x3f, 0x34, 0xb3, 0xd9, 0x52, 0x06, 0x28, 0x26, 0xa7, 0x95, 0x11, 0x62, 0x4f,
|
||||
0x15, 0x0a, 0x42, 0x40, 0x25, 0x10, 0x6a, 0x89, 0x04, 0xe2, 0x52, 0x59, 0xe2, 0xc4, 0x69, 0x93,
|
||||
0x1d, 0x35, 0xa8, 0xcb, 0x7a, 0xb1, 0x53, 0xda, 0x3c, 0x05, 0x2f, 0xc2, 0x1b, 0xf1, 0x32, 0xc8,
|
||||
0xf6, 0xba, 0x9b, 0xb4, 0x95, 0x50, 0xe8, 0x6d, 0xbe, 0xf1, 0xcc, 0xf7, 0x8d, 0xfd, 0x8d, 0x0c,
|
||||
0xc3, 0x69, 0xa9, 0xa6, 0x74, 0xb1, 0x5f, 0x6b, 0xb5, 0x50, 0xd8, 0xf7, 0x48, 0xbc, 0x84, 0xde,
|
||||
0x44, 0x6b, 0xa5, 0x11, 0xa1, 0x3b, 0x53, 0x05, 0x71, 0x96, 0xb2, 0x2c, 0x91, 0x2e, 0x46, 0x0e,
|
||||
0x77, 0xbe, 0x93, 0x31, 0xf9, 0x09, 0xf1, 0x28, 0x65, 0xd9, 0x40, 0x06, 0x28, 0xee, 0xc3, 0xbd,
|
||||
0x63, 0xfd, 0x6d, 0x46, 0x47, 0x73, 0x9a, 0x9d, 0x4a, 0xfa, 0x71, 0x46, 0x66, 0x21, 0xbe, 0x02,
|
||||
0xae, 0x26, 0x4d, 0xad, 0x2a, 0x43, 0xf8, 0x04, 0x7a, 0x64, 0x15, 0x1c, 0x73, 0x3c, 0x4e, 0xf6,
|
||||
0x9b, 0x39, 0x9c, 0xac, 0xf4, 0x67, 0x98, 0x42, 0x5c, 0xd0, 0x39, 0x2d, 0xcd, 0x31, 0xe9, 0xcf,
|
||||
0x87, 0x4e, 0xad, 0x2b, 0x57, 0x53, 0xe2, 0x19, 0x24, 0x1f, 0x73, 0x33, 0x27, 0xd3, 0xa8, 0xe1,
|
||||
0x1e, 0xf4, 0xe7, 0x2e, 0xc1, 0x59, 0xda, 0xc9, 0x06, 0xb2, 0x41, 0xe2, 0x37, 0x83, 0x9d, 0x50,
|
||||
0xb9, 0xc9, 0x08, 0x07, 0x97, 0x7c, 0x51, 0xda, 0xc9, 0xe2, 0xb1, 0x08, 0x55, 0xeb, 0x64, 0x0d,
|
||||
0x9c, 0x54, 0x0b, 0xbd, 0x0c, 0x9a, 0xa3, 0x37, 0x10, 0xaf, 0xa4, 0x71, 0x17, 0x3a, 0xa7, 0xb4,
|
||||
0x74, 0x6a, 0x03, 0x69, 0x43, 0x7c, 0x00, 0xbd, 0x9f, 0x79, 0x79, 0xe6, 0xdf, 0x71, 0x5b, 0x7a,
|
||||
0x70, 0x10, 0xbd, 0x66, 0xe2, 0x29, 0xdc, 0xfd, 0xa0, 0xce, 0xab, 0x52, 0xe5, 0x45, 0xb8, 0x19,
|
||||
0x42, 0xd7, 0xf2, 0x36, 0xfd, 0x2e, 0x16, 0xbf, 0x18, 0xec, 0xb6, 0x75, 0x9b, 0xdc, 0x2b, 0xb0,
|
||||
0x45, 0x2d, 0x9b, 0xcd, 0xd9, 0x52, 0xde, 0x49, 0x59, 0x36, 0x94, 0x2e, 0xb6, 0x66, 0xe7, 0x45,
|
||||
0xa1, 0xc9, 0x18, 0xde, 0xf5, 0x66, 0x37, 0xd0, 0x0e, 0x5f, 0x5b, 0x5f, 0x79, 0xcf, 0xd9, 0xe2,
|
||||
0x81, 0x78, 0x05, 0xc9, 0x97, 0xfa, 0x1f, 0x63, 0x5f, 0x0a, 0x45, 0xad, 0x90, 0xf8, 0x04, 0x3b,
|
||||
0xa1, 0xf1, 0x96, 0xf7, 0x18, 0xff, 0x89, 0x60, 0x78, 0x58, 0xaa, 0xe9, 0xe4, 0x62, 0x36, 0xcf,
|
||||
0xab, 0x13, 0xc2, 0x09, 0x40, 0xbb, 0x82, 0xf8, 0x38, 0x10, 0x5d, 0xdb, 0xd5, 0xd1, 0xe8, 0xa6,
|
||||
0x23, 0x3f, 0x8e, 0xd8, 0xc2, 0xf7, 0x90, 0x84, 0xc7, 0xf6, 0x4c, 0x0f, 0xaf, 0x2e, 0x83, 0x67,
|
||||
0xd9, 0xbb, 0x79, 0x47, 0xc4, 0x16, 0x1e, 0xc1, 0x76, 0x60, 0xc0, 0x47, 0xa1, 0xea, 0x8a, 0xd1,
|
||||
0x23, 0x7e, 0xfd, 0x20, 0x10, 0x64, 0xec, 0x39, 0xc3, 0x77, 0x10, 0xfb, 0x97, 0xfa, 0xcf, 0x21,
|
||||
0xde, 0x42, 0xdf, 0xf7, 0xb7, 0xad, 0x6b, 0x96, 0xb5, 0xad, 0xeb, 0x86, 0x78, 0xf9, 0x69, 0xdf,
|
||||
0x7d, 0x15, 0x2f, 0xfe, 0x06, 0x00, 0x00, 0xff, 0xff, 0x1a, 0x4a, 0x7e, 0x89, 0x3a, 0x04, 0x00,
|
||||
0x00,
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package blobex;
|
||||
|
||||
/*
|
||||
|
||||
## Errors
|
||||
- invalid request
|
||||
- banned for nonpayment
|
||||
- banned for uploading unwanted blobs
|
||||
- blob not wanted
|
||||
- blob not available
|
||||
- not accepting blobs
|
||||
|
||||
## Considerations
|
||||
|
||||
- there are two requests to upload a blob. how to reduce that to one?
|
||||
- UploadCheck checks for many hashes at once. if you're just uploading one or a few, just do it and handle the error
|
||||
|
||||
- how to avoid receiving the whole blob and then determining the blob is not wanted? may not ever be possible
|
||||
|
||||
- is avail check necessary? just request what you want for download
|
||||
- maybe you want to check multiple blobs at once?
|
||||
|
||||
- how to check for wanted blobs from stream hash?
|
||||
|
||||
- prices should be set by hosts, since they are offering blobs for download and have the best information on prices. but request is initiated by client. how do we make sure clients are not overpaying without making them make two requests for each blob?
|
||||
|
||||
- should we have another request to submit proof of payment? or at least a txid?
|
||||
|
||||
*/
|
||||
|
||||
service BlobExchange {
|
||||
rpc PriceCheck(PriceCheckRequest) returns (PriceCheckResponse) {}
|
||||
rpc DownloadCheck(HashesRequest) returns (HashesResponse) {}
|
||||
rpc Download(stream DownloadRequest) returns (stream DownloadResponse) {}
|
||||
rpc UploadCheck(HashesRequest) returns (HashesResponse) {}
|
||||
rpc Upload(stream UploadRequest) returns (stream UploadResponse) {}
|
||||
}
|
||||
|
||||
message Error {
|
||||
// should we enum the error codes?
|
||||
uint32 code = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
// how much does the host charge per kb at the moment
|
||||
message PriceCheckRequest {
|
||||
}
|
||||
message PriceCheckResponse{
|
||||
Error error = 1;
|
||||
uint64 deweysPerKB = 2;
|
||||
}
|
||||
|
||||
// are any of the hashs available for download, or are any of the hashes desired for upload
|
||||
// NOTE: if any hashes are stream hashes, and the server has the manifest but not all the content
|
||||
// blobs, the server may reply that it needs extra blobs that were not in the original request
|
||||
message HashesRequest {
|
||||
repeated string hashes = 1;
|
||||
}
|
||||
message HashesResponse {
|
||||
Error error = 1;
|
||||
map<string, bool> hashes = 2;
|
||||
}
|
||||
|
||||
// download the hash
|
||||
message DownloadRequest {
|
||||
string hash = 1;
|
||||
}
|
||||
message DownloadResponse {
|
||||
Error error = 1;
|
||||
string hash = 2;
|
||||
bytes blob = 3;
|
||||
string address = 4; // address where payment for data download should be sent
|
||||
uint64 price = 5; // price of the data in this blob
|
||||
}
|
||||
|
||||
// upload the hash
|
||||
message UploadRequest {
|
||||
string hash = 1;
|
||||
bytes blob = 2;
|
||||
}
|
||||
message UploadResponse {
|
||||
Error error = 1;
|
||||
string hash = 2;
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
#set -x
|
||||
|
||||
version_gte() {
|
||||
[ "$1" = "$(echo -e "$1\n$2" | sort -V | tail -n1)" ]
|
||||
}
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
|
||||
hash protoc 2>/dev/null || { echo >&2 -e 'error: protoc binary not found\nDownload it from https://github.com/google/protobuf/releases and put it in your path.\nMake sure you get the one starting with `protoc`, not `protobuf`.'; exit 1; }
|
||||
|
||||
|
||||
PROTOC="$(which protoc)"
|
||||
VERSION="$($PROTOC --version | cut -d' ' -f2)"
|
||||
MIN_VERSION="3.0"
|
||||
|
||||
version_gte "$VERSION" "$MIN_VERSION" || { echo >&2 "error: protoc version must be >= $MIN_VERSION (your $PROTOC is $VERSION)"; exit 1; }
|
||||
|
||||
|
||||
hash protoc-gen-go 2>/dev/null || go get -u github.com/golang/protobuf/protoc-gen-go
|
||||
hash protoc-gen-go 2>/dev/null || { echo >&2 'error: Make sure $GOPATH/bin is in your $PATH'; exit 1; }
|
||||
|
||||
|
||||
find . -type f -iname '*.pb.go' -delete
|
||||
|
||||
protoc --proto_path=. blobex.proto --go_out=plugins=grpc:.
|
||||
@@ -1,49 +0,0 @@
|
||||
package blobex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
pricePerKB uint64
|
||||
}
|
||||
|
||||
func ListenAndServe(port int) (*grpc.Server, error) {
|
||||
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
if err != nil {
|
||||
return nil, errors.Prefix("failed to listen", err)
|
||||
}
|
||||
grpcServer := grpc.NewServer()
|
||||
RegisterBlobExchangeServer(grpcServer, &Server{})
|
||||
// determine whether to use TLS
|
||||
err = grpcServer.Serve(listener)
|
||||
return grpcServer, err
|
||||
}
|
||||
|
||||
func (s *Server) PriceCheck(ctx context.Context, r *PriceCheckRequest) (*PriceCheckResponse, error) {
|
||||
return &PriceCheckResponse{
|
||||
DeweysPerKB: s.pricePerKB,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Server) DownloadCheck(context.Context, *HashesRequest) (*HashesResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) Download(BlobExchange_DownloadServer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) UploadCheck(context.Context, *HashesRequest) (*HashesResponse, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *Server) Upload(BlobExchange_UploadServer) error {
|
||||
return nil
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ package claim
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
types "github.com/lbryio/types/v1/go"
|
||||
types "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package claim
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/lbryio/lbcd/txscript"
|
||||
"github.com/lbryio/lbcutil"
|
||||
)
|
||||
|
||||
func ClaimSupportPayoutScript(name, claimid string, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_SUPPORT_CLAIM <name> <claimid> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_SUPPORTCLAIM). //OP_SUPPORT_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
|
||||
}
|
||||
|
||||
func ClaimNamePayoutScript(name string, value []byte, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_CLAIM_NAME <name> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_CLAIMNAME). //OP_CLAIMNAME
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
|
||||
func UpdateClaimPayoutScript(name, claimid string, value []byte, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_UPDATE_CLAIM <name> <claimid> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_UPDATECLAIM). //OP_UPDATE_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
|
||||
// rev reverses a byte slice. useful for switching endian-ness
|
||||
func rev(b []byte) []byte {
|
||||
r := make([]byte, len(b))
|
||||
for left, right := 0, len(b)-1; left < right; left, right = left+1, right-1 {
|
||||
r[left], r[right] = b[right], b[left]
|
||||
}
|
||||
return r
|
||||
}
|
||||
+4
-4
@@ -7,7 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/cockroachdb/errors"
|
||||
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
@@ -254,7 +254,7 @@ func (b *Bitmap) UnmarshalBencode(encoded []byte) error {
|
||||
return err
|
||||
}
|
||||
if len(str) != NumBytes {
|
||||
return errors.Err("invalid bitmap length")
|
||||
return errors.WithStack(errors.New("invalid bitmap length"))
|
||||
}
|
||||
copy(b[:], str)
|
||||
return nil
|
||||
@@ -265,7 +265,7 @@ func FromBytes(data []byte) (Bitmap, error) {
|
||||
var bmp Bitmap
|
||||
|
||||
if len(data) != len(bmp) {
|
||||
return bmp, errors.Err("invalid bitmap of length %d", len(data))
|
||||
return bmp, errors.WithStack(errors.Newf("invalid bitmap of length %d", len(data)))
|
||||
}
|
||||
|
||||
copy(bmp[:], data)
|
||||
@@ -303,7 +303,7 @@ func FromStringP(data string) Bitmap {
|
||||
func FromHex(hexStr string) (Bitmap, error) {
|
||||
decoded, err := hex.DecodeString(hexStr)
|
||||
if err != nil {
|
||||
return Bitmap{}, errors.Err(err)
|
||||
return Bitmap{}, errors.WithStack(err)
|
||||
}
|
||||
return FromBytes(decoded)
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ package bits
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
"github.com/lbryio/errors.go"
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
// Range has a start and end
|
||||
@@ -24,7 +24,7 @@ func MaxRange() Range {
|
||||
// the first interval always starts at the beginning of the range, and the last interval always ends at the end
|
||||
func (r Range) IntervalP(n, num int) Range {
|
||||
if num < 1 || n < 1 || n > num {
|
||||
panic(errors.Err("invalid interval %d of %d", n, num))
|
||||
panic(errors.WithStack(errors.Newf("invalid interval %d of %d", n, num)))
|
||||
}
|
||||
|
||||
start := r.intervalStart(n, num)
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
func TestBootstrapPing(t *testing.T) {
|
||||
|
||||
+6
-5
@@ -4,7 +4,7 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
|
||||
// TODO: all these constants should be defaults, and should be used to set values in the standard Config. then the code should use values in the config
|
||||
// TODO: alternatively, have a global Config for constants. at least that way tests can modify the values
|
||||
alpha = 3 // this is the constant alpha in the spec
|
||||
alpha = 5 // this is the constant alpha in the spec
|
||||
bucketSize = 8 // this is the constant k in the spec
|
||||
nodeIDLength = bits.NumBytes // bytes. this is the constant B in the spec
|
||||
messageIDLength = 20 // bytes.
|
||||
@@ -65,9 +65,10 @@ func NewStandardConfig() *Config {
|
||||
return &Config{
|
||||
Address: "0.0.0.0:" + strconv.Itoa(DefaultPort),
|
||||
SeedNodes: []string{
|
||||
"lbrynet1.lbry.io:4444",
|
||||
"lbrynet2.lbry.io:4444",
|
||||
"lbrynet3.lbry.io:4444",
|
||||
"lbrynet1.lbry.com:4444",
|
||||
"lbrynet2.lbry.com:4444",
|
||||
"lbrynet3.lbry.com:4444",
|
||||
"lbrynet4.lbry.com:4444",
|
||||
},
|
||||
PeerProtocolPort: DefaultPeerPort,
|
||||
ReannounceTime: DefaultReannounceTime,
|
||||
|
||||
+23
-8
@@ -2,13 +2,14 @@ package dht
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
@@ -41,14 +42,28 @@ func (c Contact) String() string {
|
||||
return str
|
||||
}
|
||||
|
||||
func (c Contact) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(&struct {
|
||||
ID string
|
||||
IP string
|
||||
Port int
|
||||
PeerPort int
|
||||
}{
|
||||
ID: c.ID.Hex(),
|
||||
IP: c.IP.String(),
|
||||
Port: c.Port,
|
||||
PeerPort: c.PeerPort,
|
||||
})
|
||||
}
|
||||
|
||||
// MarshalCompact returns a compact byteslice representation of the contact
|
||||
// NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it
|
||||
func (c Contact) MarshalCompact() ([]byte, error) {
|
||||
if c.IP.To4() == nil {
|
||||
return nil, errors.Err("ip not set")
|
||||
return nil, errors.WithStack(errors.New("ip not set"))
|
||||
}
|
||||
if c.PeerPort < 0 || c.PeerPort > 65535 {
|
||||
return nil, errors.Err("invalid port")
|
||||
return nil, errors.WithStack(errors.New("invalid port"))
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
@@ -58,7 +73,7 @@ func (c Contact) MarshalCompact() ([]byte, error) {
|
||||
buf.Write(c.ID[:])
|
||||
|
||||
if buf.Len() != compactNodeInfoLength {
|
||||
return nil, errors.Err("i dont know how this happened")
|
||||
return nil, errors.WithStack(errors.New("i dont know how this happened"))
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
@@ -68,7 +83,7 @@ func (c Contact) MarshalCompact() ([]byte, error) {
|
||||
// NOTE: The compact representation always uses the tcp PeerPort, not the udp Port. This is dumb, but that's how the python daemon does it
|
||||
func (c *Contact) UnmarshalCompact(b []byte) error {
|
||||
if len(b) != compactNodeInfoLength {
|
||||
return errors.Err("invalid compact length")
|
||||
return errors.WithStack(errors.New("invalid compact length"))
|
||||
}
|
||||
c.IP = net.IPv4(b[0], b[1], b[2], b[3]).To4()
|
||||
c.PeerPort = int(uint16(b[5]) | uint16(b[4])<<8)
|
||||
@@ -90,7 +105,7 @@ func (c *Contact) UnmarshalBencode(b []byte) error {
|
||||
}
|
||||
|
||||
if len(raw) != 3 {
|
||||
return errors.Err("contact must have 3 elements; got %d", len(raw))
|
||||
return errors.WithStack(errors.Newf("contact must have 3 elements; got %d", len(raw)))
|
||||
}
|
||||
|
||||
err = bencode.DecodeBytes(raw[0], &c.ID)
|
||||
@@ -105,7 +120,7 @@ func (c *Contact) UnmarshalBencode(b []byte) error {
|
||||
}
|
||||
c.IP = net.ParseIP(ipStr).To4()
|
||||
if c.IP == nil {
|
||||
return errors.Err("invalid IP")
|
||||
return errors.WithStack(errors.New("invalid IP"))
|
||||
}
|
||||
|
||||
return bencode.DecodeBytes(raw[2], &c.Port)
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
func TestCompactEncoding(t *testing.T) {
|
||||
|
||||
+11
-11
@@ -6,10 +6,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -76,7 +76,7 @@ func (dht *DHT) connect(conn UDPConn) error {
|
||||
func (dht *DHT) Start() error {
|
||||
listener, err := net.ListenPacket(Network, dht.conf.Address)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
conn := listener.(*net.UDPConn)
|
||||
|
||||
@@ -117,7 +117,7 @@ func (dht *DHT) join() {
|
||||
for _, addr := range dht.conf.SeedNodes {
|
||||
err := dht.Ping(addr)
|
||||
if err != nil {
|
||||
log.Error(errors.Prefix(fmt.Sprintf("[%s] join", dht.node.id.HexShort()), err))
|
||||
log.Error(errors.WithMessage(err, fmt.Sprintf("[%s] join", dht.node.id.HexShort())))
|
||||
} else {
|
||||
atLeastOneNodeResponded = true
|
||||
}
|
||||
@@ -165,7 +165,7 @@ func (dht *DHT) Ping(addr string) error {
|
||||
tmpNode := Contact{ID: bits.Rand(), IP: raddr.IP, Port: raddr.Port}
|
||||
res := dht.node.Send(tmpNode, Request{Method: pingMethod}, SendOptions{skipIDCheck: true})
|
||||
if res == nil {
|
||||
return errors.Err("no response from node %s", addr)
|
||||
return errors.WithStack(errors.Newf("no response from node %s", addr))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -210,21 +210,21 @@ func getContact(nodeID, addr string) (Contact, error) {
|
||||
|
||||
ip, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return c, errors.Err(err)
|
||||
return c, errors.WithStack(err)
|
||||
} else if ip == "" {
|
||||
return c, errors.Err("address does not contain an IP")
|
||||
return c, errors.WithStack(errors.New("address does not contain an IP"))
|
||||
} else if port == "" {
|
||||
return c, errors.Err("address does not contain a port")
|
||||
return c, errors.WithStack(errors.New("address does not contain a port"))
|
||||
}
|
||||
|
||||
c.IP = net.ParseIP(ip)
|
||||
if c.IP == nil {
|
||||
return c, errors.Err("invalid ip")
|
||||
return c, errors.WithStack(errors.New("invalid ip"))
|
||||
}
|
||||
|
||||
c.Port, err = cast.ToIntE(port)
|
||||
if err != nil {
|
||||
return c, errors.Err(err)
|
||||
return c, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
|
||||
+6
-5
@@ -7,10 +7,11 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
type queueEdit struct {
|
||||
@@ -60,7 +61,7 @@ func (dht *DHT) runAnnouncer() {
|
||||
for {
|
||||
err := limiter.Wait(context.Background()) // TODO: should use grp.ctx somehow? so when grp is closed, wait returns
|
||||
if err != nil {
|
||||
log.Error(errors.Prefix("rate limiter", err))
|
||||
log.Error(errors.WithMessage(err, "rate limiter"))
|
||||
continue
|
||||
}
|
||||
select {
|
||||
@@ -145,7 +146,7 @@ func (dht *DHT) runAnnouncer() {
|
||||
defer dht.grp.Done()
|
||||
err := dht.announce(hash)
|
||||
if err != nil {
|
||||
log.Error(errors.Prefix("announce", err))
|
||||
log.Error(errors.WithMessage(err, "announce"))
|
||||
}
|
||||
|
||||
if dht.conf.AnnounceNotificationCh != nil {
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
func TestNodeFinder_FindNodes(t *testing.T) {
|
||||
|
||||
+37
-28
@@ -7,9 +7,9 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/lyoshenka/bencode"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
@@ -40,6 +40,7 @@ const (
|
||||
headerPayloadField = "3"
|
||||
headerArgsField = "4"
|
||||
contactsField = "contacts"
|
||||
pageField = "p"
|
||||
tokenField = "token"
|
||||
protocolVersionField = "protocolVersion"
|
||||
)
|
||||
@@ -67,7 +68,7 @@ func (m *messageID) UnmarshalBencode(encoded []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshallBencode returns the encoded byte slice of the message id.
|
||||
// MarshalBencode returns the encoded byte slice of the message id.
|
||||
func (m messageID) MarshalBencode() ([]byte, error) {
|
||||
str := string(m[:])
|
||||
return bencode.EncodeBytes(str)
|
||||
@@ -121,7 +122,7 @@ func (r *Request) UnmarshalBencode(b []byte) error {
|
||||
}
|
||||
err := bencode.DecodeBytes(b, &raw)
|
||||
if err != nil {
|
||||
return errors.Prefix("request unmarshal", err)
|
||||
return errors.WithMessage(err, "request unmarshal")
|
||||
}
|
||||
|
||||
r.ID = raw.ID
|
||||
@@ -132,12 +133,12 @@ func (r *Request) UnmarshalBencode(b []byte) error {
|
||||
r.StoreArgs = &storeArgs{} // bencode wont find the unmarshaler on a null pointer. need to fix it.
|
||||
err = bencode.DecodeBytes(raw.Args, &r.StoreArgs)
|
||||
if err != nil {
|
||||
return errors.Prefix("request unmarshal", err)
|
||||
return errors.WithMessage(err, "request unmarshal")
|
||||
}
|
||||
} else if len(raw.Args) > 2 { // 2 because an empty list is `le`
|
||||
r.Arg, r.ProtocolVersion, err = processArgsAndProtoVersion(raw.Args)
|
||||
if err != nil {
|
||||
return errors.Prefix("request unmarshal", err)
|
||||
return errors.WithMessage(err, "request unmarshal")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,39 +224,39 @@ func (s *storeArgs) UnmarshalBencode(b []byte) error {
|
||||
var argsInt []bencode.RawMessage
|
||||
err := bencode.DecodeBytes(b, &argsInt)
|
||||
if err != nil {
|
||||
return errors.Prefix("storeArgs unmarshal", err)
|
||||
return errors.WithMessage(err, "storeArgs unmarshal")
|
||||
}
|
||||
|
||||
if len(argsInt) != 4 {
|
||||
return errors.Err("unexpected number of fields for store args. got " + cast.ToString(len(argsInt)))
|
||||
return errors.WithStack(errors.Newf("unexpected number of fields for store args. got %d", len(argsInt)))
|
||||
}
|
||||
|
||||
err = bencode.DecodeBytes(argsInt[0], &s.BlobHash)
|
||||
if err != nil {
|
||||
return errors.Prefix("storeArgs unmarshal", err)
|
||||
return errors.WithMessage(err, "storeArgs unmarshal")
|
||||
}
|
||||
|
||||
err = bencode.DecodeBytes(argsInt[1], &s.Value)
|
||||
if err != nil {
|
||||
return errors.Prefix("storeArgs unmarshal", err)
|
||||
return errors.WithMessage(err, "storeArgs unmarshal")
|
||||
}
|
||||
|
||||
err = bencode.DecodeBytes(argsInt[2], &s.NodeID)
|
||||
if err != nil {
|
||||
return errors.Prefix("storeArgs unmarshal", err)
|
||||
return errors.WithMessage(err, "storeArgs unmarshal")
|
||||
}
|
||||
|
||||
var selfStore int
|
||||
err = bencode.DecodeBytes(argsInt[3], &selfStore)
|
||||
if err != nil {
|
||||
return errors.Prefix("storeArgs unmarshal", err)
|
||||
return errors.WithMessage(err, "storeArgs unmarshal")
|
||||
}
|
||||
if selfStore == 0 {
|
||||
s.SelfStore = false
|
||||
} else if selfStore == 1 {
|
||||
s.SelfStore = true
|
||||
} else {
|
||||
return errors.Err("selfstore must be 1 or 0")
|
||||
return errors.WithStack(errors.New("selfstore must be 1 or 0"))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -270,6 +271,7 @@ type Response struct {
|
||||
FindValueKey string
|
||||
Token string
|
||||
ProtocolVersion int
|
||||
Page uint8
|
||||
}
|
||||
|
||||
func (r Response) argsDebug() string {
|
||||
@@ -309,7 +311,7 @@ func (r Response) MarshalBencode() ([]byte, error) {
|
||||
} else if r.FindValueKey != "" {
|
||||
// findValue success
|
||||
if r.Token == "" {
|
||||
return nil, errors.Err("response to findValue must have a token")
|
||||
return nil, errors.WithStack(errors.New("response to findValue must have a token"))
|
||||
}
|
||||
|
||||
var contacts [][]byte
|
||||
@@ -390,27 +392,34 @@ func (r *Response) UnmarshalBencode(b []byte) error {
|
||||
|
||||
if contacts, ok := rawData[contactsField]; ok {
|
||||
err = bencode.DecodeBytes(contacts, &r.Contacts)
|
||||
delete(rawData, contactsField) // so it doesnt mess up findValue key finding below
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
for k, v := range rawData {
|
||||
r.FindValueKey = k
|
||||
var compactContacts [][]byte
|
||||
err = bencode.DecodeBytes(v, &compactContacts)
|
||||
}
|
||||
if page, ok := rawData[pageField]; ok {
|
||||
err = bencode.DecodeBytes(page, &r.Page)
|
||||
delete(rawData, pageField) // so it doesnt mess up findValue key finding below
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for k, v := range rawData {
|
||||
r.FindValueKey = k
|
||||
var compactContacts [][]byte
|
||||
err = bencode.DecodeBytes(v, &compactContacts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, compact := range compactContacts {
|
||||
var c Contact
|
||||
err = c.UnmarshalCompact(compact)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, compact := range compactContacts {
|
||||
var c Contact
|
||||
err = c.UnmarshalCompact(compact)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.Contacts = append(r.Contacts, c)
|
||||
}
|
||||
break
|
||||
r.Contacts = append(r.Contacts, c)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lyoshenka/bencode"
|
||||
|
||||
+7
-8
@@ -7,12 +7,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/extras/util"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
@@ -163,7 +161,8 @@ func (n *Node) Shutdown() {
|
||||
func (n *Node) handlePacket(pkt packet) {
|
||||
//log.Debugf("[%s] Received message from %s (%d bytes) %s", n.id.HexShort(), pkt.raddr.String(), len(pkt.data), hex.EncodeToString(pkt.data))
|
||||
|
||||
if !util.InSlice(string(pkt.data[0:5]), []string{"d1:0i", "di0ei"}) {
|
||||
firstFive := string(pkt.data[0:5])
|
||||
if firstFive != "d1:0i" && firstFive != "di0ei" {
|
||||
log.Errorf("[%s] data is not a well-formatted dict: (%d bytes) %s", n.id.HexShort(), len(pkt.data), hex.EncodeToString(pkt.data))
|
||||
return
|
||||
}
|
||||
@@ -318,7 +317,7 @@ func (n *Node) handleError(addr *net.UDPAddr, e Error) {
|
||||
func (n *Node) sendMessage(addr *net.UDPAddr, data Message) error {
|
||||
encoded, err := bencode.EncodeBytes(data)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if req, ok := data.(Request); ok {
|
||||
@@ -340,7 +339,7 @@ func (n *Node) sendMessage(addr *net.UDPAddr, data Message) error {
|
||||
}
|
||||
|
||||
_, err = n.conn.WriteToUDP(encoded, addr)
|
||||
return errors.Err(err)
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
// transaction represents a single query to the dht. it stores the queried contact, the request, and the response channel
|
||||
|
||||
+27
-7
@@ -1,16 +1,17 @@
|
||||
package dht
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/crypto"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/uber-go/atomic"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
// TODO: iterativeFindValue may be stopping early. if it gets a response with one peer, it should keep going because other nodes may know about more peers that have that blob
|
||||
@@ -78,7 +79,10 @@ func (cf *contactFinder) Find() ([]Contact, bool, error) {
|
||||
|
||||
cf.appendNewToShortlist(cf.node.rt.GetClosest(cf.target, alpha))
|
||||
if len(cf.shortlist) == 0 {
|
||||
return nil, false, errors.Err("[%s] find %s: no contacts in routing table", cf.node.id.HexShort(), cf.target.HexShort())
|
||||
return nil, false, errors.WithStack(errors.Newf(
|
||||
"[%s] find %s: no contacts in routing table",
|
||||
cf.node.id.HexShort(), cf.target.HexShort(),
|
||||
))
|
||||
}
|
||||
|
||||
go cf.cycle(false)
|
||||
@@ -113,7 +117,7 @@ CycleLoop:
|
||||
|
||||
// cycle does a single cycle of sending alpha probes and checking results against closestNode
|
||||
func (cf *contactFinder) cycle(bigCycle bool) {
|
||||
cycleID := crypto.RandString(6)
|
||||
cycleID := randString(6)
|
||||
if bigCycle {
|
||||
cf.debug("LAUNCHING CYCLE %s, AND ITS A BIG CYCLE", cycleID)
|
||||
} else {
|
||||
@@ -336,3 +340,19 @@ func (cf *contactFinder) closest(contacts ...Contact) *Contact {
|
||||
}
|
||||
return &closest
|
||||
}
|
||||
|
||||
// randString returns a random alphanumeric string of a given length
|
||||
func randString(length int) string {
|
||||
buf := make([]byte, length/2)
|
||||
_, err := rand.Reader.Read(buf)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
randStr := hex.EncodeToString(buf)[:length]
|
||||
if len(randStr) < length {
|
||||
panic("Could not create random string that is long enough")
|
||||
}
|
||||
|
||||
return randStr
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lyoshenka/bencode"
|
||||
)
|
||||
|
||||
|
||||
+11
-10
@@ -9,9 +9,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
// TODO: if routing table is ever empty (aka the node is isolated), it should re-bootstrap
|
||||
@@ -40,7 +41,7 @@ func (p *peer) Touch() {
|
||||
p.NumFailures = 0
|
||||
}
|
||||
|
||||
// ActiveSince returns whether a peer has responded in the last `d` duration
|
||||
// ActiveInLast returns whether a peer has responded in the last `d` duration
|
||||
// this is used to check if the peer is "good", meaning that we believe the peer will respond to our requests
|
||||
func (p *peer) ActiveInLast(d time.Duration) bool {
|
||||
return time.Since(p.LastActivity) < d
|
||||
@@ -106,7 +107,7 @@ func (b *bucket) UpdatePeer(p peer, insertIfNew bool) error {
|
||||
defer b.lock.Unlock()
|
||||
|
||||
if !b.Range.Contains(p.Distance) {
|
||||
return errors.Err("this bucket range does not cover this peer")
|
||||
return errors.WithStack(errors.New("this bucket range does not cover this peer"))
|
||||
}
|
||||
|
||||
peerIndex := find(p.Contact.ID, b.peers)
|
||||
@@ -404,27 +405,27 @@ func (rt *routingTable) UnmarshalJSON(b []byte) error {
|
||||
|
||||
rt.id, err = bits.FromHex(data.ID)
|
||||
if err != nil {
|
||||
return errors.Prefix("decoding ID", err)
|
||||
return errors.WithMessage(err, "decoding ID")
|
||||
}
|
||||
rt.reset()
|
||||
|
||||
for _, s := range data.Contacts {
|
||||
parts := strings.Split(s, rtContactSep)
|
||||
if len(parts) != 3 {
|
||||
return errors.Err("decoding contact %s: wrong number of parts", s)
|
||||
return errors.WithStack(errors.Newf("decoding contact %s: wrong number of parts", s))
|
||||
}
|
||||
var c Contact
|
||||
c.ID, err = bits.FromHex(parts[0])
|
||||
if err != nil {
|
||||
return errors.Err("decoding contact %s: invalid ID: %s", s, err)
|
||||
return errors.WithStack(errors.Newf("decoding contact %s: invalid ID: %s", s, err))
|
||||
}
|
||||
c.IP = net.ParseIP(parts[1])
|
||||
if c.IP == nil {
|
||||
return errors.Err("decoding contact %s: invalid IP", s)
|
||||
return errors.WithStack(errors.Newf("decoding contact %s: invalid IP", s))
|
||||
}
|
||||
c.Port, err = strconv.Atoi(parts[2])
|
||||
if err != nil {
|
||||
return errors.Err("decoding contact %s: invalid port: %s", s, err)
|
||||
return errors.WithStack(errors.Newf("decoding contact %s: invalid port: %s", s, err))
|
||||
}
|
||||
rt.Update(c)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/sebdah/goldie"
|
||||
)
|
||||
|
||||
+15
-7
@@ -7,9 +7,9 @@ import (
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/gorilla/mux"
|
||||
rpc2 "github.com/gorilla/rpc/v2"
|
||||
"github.com/gorilla/rpc/v2/json"
|
||||
@@ -25,7 +25,7 @@ type RpcPingArgs struct {
|
||||
|
||||
func (rpc *rpcReceiver) Ping(r *http.Request, args *RpcPingArgs, result *string) error {
|
||||
if args.Address == "" {
|
||||
return errors.Err("no address given")
|
||||
return errors.WithStack(errors.New("no address given"))
|
||||
}
|
||||
|
||||
err := rpc.dht.Ping(args.Address)
|
||||
@@ -92,7 +92,7 @@ func (rpc *rpcReceiver) FindValue(r *http.Request, args *RpcFindArgs, result *Rp
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.Err("not sure what happened")
|
||||
return errors.WithStack(errors.New("not sure what happened"))
|
||||
}
|
||||
|
||||
type RpcIterativeFindValueArgs struct {
|
||||
@@ -102,6 +102,7 @@ type RpcIterativeFindValueArgs struct {
|
||||
type RpcIterativeFindValueResult struct {
|
||||
Contacts []Contact
|
||||
FoundValue bool
|
||||
Values []Contact
|
||||
}
|
||||
|
||||
func (rpc *rpcReceiver) IterativeFindValue(r *http.Request, args *RpcIterativeFindValueArgs, result *RpcIterativeFindValueResult) error {
|
||||
@@ -109,12 +110,19 @@ func (rpc *rpcReceiver) IterativeFindValue(r *http.Request, args *RpcIterativeFi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
foundContacts, found, err := FindContacts(rpc.dht.node, key, false, nil)
|
||||
foundContacts, found, err := FindContacts(rpc.dht.node, key, true, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
result.Contacts = foundContacts
|
||||
result.FoundValue = found
|
||||
if found {
|
||||
for _, contact := range foundContacts {
|
||||
if contact.PeerPort > 0 {
|
||||
result.Values = append(result.Values, contact)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -158,7 +166,7 @@ func (dht *DHT) runRPCServer(port int) {
|
||||
s.RegisterCodec(json.NewCodec(), "application/json;charset=UTF-8")
|
||||
err := s.RegisterService(&rpcReceiver{dht: dht}, "rpc")
|
||||
if err != nil {
|
||||
log.Error(errors.Prefix("registering rpc service", err))
|
||||
log.Error(errors.WithMessage(err, "registering rpc service"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -180,7 +188,7 @@ func (dht *DHT) runRPCServer(port int) {
|
||||
<-dht.grp.Ch()
|
||||
err = server.Shutdown(context.Background())
|
||||
if err != nil {
|
||||
log.Error(errors.Prefix("shutting down rpc service", err))
|
||||
log.Error(errors.WithMessage(err, "shutting down rpc service"))
|
||||
return
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package dht
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
)
|
||||
|
||||
// TODO: expire stored data after tExpire time
|
||||
|
||||
+5
-4
@@ -7,8 +7,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
var testingDHTIP = "127.0.0.1"
|
||||
@@ -121,12 +122,12 @@ func (t testUDPConn) ReadFromUDP(b []byte) (int, *net.UDPAddr, error) {
|
||||
select {
|
||||
case packet, ok := <-t.toRead:
|
||||
if !ok {
|
||||
return 0, nil, errors.Err("conn closed")
|
||||
return 0, nil, errors.WithStack(errors.New("conn closed"))
|
||||
}
|
||||
n := copy(b, packet.data)
|
||||
return n, packet.addr, nil
|
||||
case <-timeoutCh:
|
||||
return 0, nil, timeoutErr{errors.Err("timeout")}
|
||||
return 0, nil, timeoutErr{errors.WithStack(errors.New("timeout"))}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
)
|
||||
|
||||
// TODO: this should be moved out of dht and into node, and it should be completely hidden inside node. dht should not need to know about tokens
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/dht/bits"
|
||||
"github.com/lbryio/lbry.go/extras/stop"
|
||||
"github.com/lbryio/lbry.go/v3/dht/bits"
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
)
|
||||
|
||||
type tokenManager struct {
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package electrum
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/v3/lbrycrd"
|
||||
"github.com/lbryio/lbry.go/v3/schema/stake"
|
||||
types "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/lbryio/lbcutil"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// Raw makes a raw wallet server request
|
||||
func (n *Node) Raw(method string, params []string, v interface{}) error {
|
||||
return n.request(method, params, v)
|
||||
}
|
||||
|
||||
// ServerVersion returns the server's version.
|
||||
// https://electrumx.readthedocs.io/en/latest/protocol-methods.html#server-version
|
||||
func (n *Node) ServerVersion() (string, error) {
|
||||
resp := &struct {
|
||||
Result []string `json:"result"`
|
||||
}{}
|
||||
err := n.request("server.version", []string{"reflector.go", ProtocolVersion}, resp)
|
||||
|
||||
var v string
|
||||
if len(resp.Result) >= 2 {
|
||||
v = resp.Result[1]
|
||||
}
|
||||
|
||||
return v, err
|
||||
}
|
||||
|
||||
func (n *Node) Resolve(url string) (*types.Output, error) {
|
||||
outputs := &types.Outputs{}
|
||||
resp := &struct {
|
||||
Result string `json:"result"`
|
||||
}{}
|
||||
|
||||
err := n.request("blockchain.claimtrie.resolve", []string{url}, resp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
b, err := base64.StdEncoding.DecodeString(resp.Result)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
err = proto.Unmarshal(b, outputs)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if len(outputs.GetTxos()) != 1 {
|
||||
return nil, errors.New("expected 1 output, got " + cast.ToString(len(outputs.GetTxos())))
|
||||
}
|
||||
|
||||
if e := outputs.GetTxos()[0].GetError(); e != nil {
|
||||
return nil, errors.Newf("%s: %s", e.GetCode(), e.GetText())
|
||||
}
|
||||
|
||||
return outputs.GetTxos()[0], nil
|
||||
}
|
||||
|
||||
type GetClaimsInTxResp struct {
|
||||
Jsonrpc string `json:"jsonrpc"`
|
||||
ID int `json:"id"`
|
||||
Result []struct {
|
||||
Name string `json:"name"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
Txid string `json:"txid"`
|
||||
Nout int `json:"nout"`
|
||||
Amount int `json:"amount"`
|
||||
Depth int `json:"depth"`
|
||||
Height int `json:"height"`
|
||||
Value string `json:"value"`
|
||||
ClaimSequence int `json:"claim_sequence"`
|
||||
Address string `json:"address"`
|
||||
Supports []interface{} `json:"supports"` // TODO: finish me
|
||||
EffectiveAmount int `json:"effective_amount"`
|
||||
ValidAtHeight int `json:"valid_at_height"`
|
||||
} `json:"result"`
|
||||
}
|
||||
|
||||
func (n *Node) GetClaimsInTx(txid string) (*GetClaimsInTxResp, error) {
|
||||
var resp GetClaimsInTxResp
|
||||
err := n.request("blockchain.claimtrie.getclaimsintx", []string{txid}, &resp)
|
||||
return &resp, err
|
||||
}
|
||||
|
||||
func (n *Node) GetTx(txid string) (string, error) {
|
||||
resp := &struct {
|
||||
Result string `json:"result"`
|
||||
}{}
|
||||
|
||||
err := n.request("blockchain.transaction.get", []string{txid}, resp)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp.Result, nil
|
||||
}
|
||||
|
||||
func (n *Node) GetClaimInTx(txid string, nout int) (*types.Claim, error) {
|
||||
hexTx, err := n.GetTx(txid)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
rawTx, err := hex.DecodeString(hexTx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
tx, err := lbcutil.NewTxFromBytes(rawTx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if len(tx.MsgTx().TxOut) <= nout {
|
||||
return nil, errors.WithStack(errors.New("nout not found"))
|
||||
}
|
||||
|
||||
script := tx.MsgTx().TxOut[nout].PkScript
|
||||
|
||||
var value []byte
|
||||
if lbrycrd.IsClaimNameScript(script) {
|
||||
_, value, _, err = lbrycrd.ParseClaimNameScript(script)
|
||||
} else if lbrycrd.IsClaimUpdateScript(script) {
|
||||
_, _, value, _, err = lbrycrd.ParseClaimUpdateScript(script)
|
||||
} else {
|
||||
err = errors.New("no claim found in output")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ch, err := stake.DecodeClaimBytes(value, "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ch.Claim, nil
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
package electrum
|
||||
|
||||
// copied from https://github.com/d4l3k/go-electrum
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
const (
|
||||
ClientVersion = "0.0.1"
|
||||
ProtocolVersion = "1.0"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotImplemented = errors.New("not implemented")
|
||||
ErrNodeConnected = errors.New("node already connected")
|
||||
ErrConnectFailed = errors.New("failed to connect")
|
||||
ErrTimeout = errors.New("timeout")
|
||||
)
|
||||
|
||||
type response struct {
|
||||
data []byte
|
||||
err error
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
transport *TCPTransport
|
||||
nextId atomic.Uint32
|
||||
grp *stop.Group
|
||||
|
||||
handlersMu *sync.RWMutex
|
||||
handlers map[uint32]chan response
|
||||
|
||||
pushHandlersMu *sync.RWMutex
|
||||
pushHandlers map[string][]chan response
|
||||
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// NewNode creates a new node.
|
||||
func NewNode() *Node {
|
||||
return &Node{
|
||||
handlers: make(map[uint32]chan response),
|
||||
pushHandlers: make(map[string][]chan response),
|
||||
handlersMu: &sync.RWMutex{},
|
||||
pushHandlersMu: &sync.RWMutex{},
|
||||
grp: stop.New(),
|
||||
timeout: 1 * time.Second,
|
||||
}
|
||||
}
|
||||
|
||||
// Connect creates a new connection to the specified address.
|
||||
func (n *Node) Connect(addrs []string, config *tls.Config) error {
|
||||
if n.transport != nil {
|
||||
return errors.WithStack(ErrNodeConnected)
|
||||
}
|
||||
|
||||
// shuffle addresses for load balancing
|
||||
rand.Shuffle(len(addrs), func(i, j int) { addrs[i], addrs[j] = addrs[j], addrs[i] })
|
||||
|
||||
var err error
|
||||
|
||||
for _, addr := range addrs {
|
||||
n.transport, err = NewTransport(addr, config)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
if errors.Is(err, ErrTimeout) {
|
||||
continue
|
||||
}
|
||||
if e, ok := err.(*net.OpError); ok && e.Err.Error() == "no such host" {
|
||||
// net.errNoSuchHost is not exported, so we have to string-match
|
||||
continue
|
||||
}
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if n.transport == nil {
|
||||
return errors.WithStack(ErrConnectFailed)
|
||||
}
|
||||
|
||||
log.Debugf("wallet connected to %s", n.transport.conn.RemoteAddr())
|
||||
|
||||
n.grp.Add(1)
|
||||
go func() {
|
||||
defer n.grp.Done()
|
||||
<-n.grp.Ch()
|
||||
n.transport.Shutdown()
|
||||
}()
|
||||
|
||||
n.grp.Add(1)
|
||||
go func() {
|
||||
defer n.grp.Done()
|
||||
n.handleErrors()
|
||||
}()
|
||||
|
||||
n.grp.Add(1)
|
||||
go func() {
|
||||
defer n.grp.Done()
|
||||
n.listen()
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *Node) Shutdown() {
|
||||
var addr net.Addr
|
||||
if n.transport != nil {
|
||||
addr = n.transport.conn.RemoteAddr()
|
||||
}
|
||||
log.Debugf("shutting down wallet %s", addr)
|
||||
n.grp.StopAndWait()
|
||||
log.Debugf("wallet stopped")
|
||||
}
|
||||
|
||||
func (n *Node) handleErrors() {
|
||||
for {
|
||||
select {
|
||||
case <-n.grp.Ch():
|
||||
return
|
||||
case err := <-n.transport.Errors():
|
||||
n.err(errors.WithStack(err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// err handles errors produced by the foreign node.
|
||||
func (n *Node) err(err error) {
|
||||
// TODO: Better error handling.
|
||||
log.Error(errors.WithStack(err))
|
||||
}
|
||||
|
||||
// listen processes messages from the server.
|
||||
func (n *Node) listen() {
|
||||
for {
|
||||
select {
|
||||
case <-n.grp.Ch():
|
||||
return
|
||||
default:
|
||||
}
|
||||
|
||||
select {
|
||||
case <-n.grp.Ch():
|
||||
return
|
||||
case bytes := <-n.transport.Responses():
|
||||
msg := &struct {
|
||||
Id uint32 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Error struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}{}
|
||||
msg2 := &struct {
|
||||
Id uint32 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Error struct {
|
||||
Code int `json:"code"`
|
||||
Message struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"message"`
|
||||
} `json:"error"`
|
||||
}{}
|
||||
r := response{}
|
||||
|
||||
err := json.Unmarshal(bytes, msg)
|
||||
if err != nil {
|
||||
// try msg2, a hack around the weird error-in-error response we sometimes get from wallet server
|
||||
// maybe that happens because the wallet server passes a lbrycrd error through to us?
|
||||
if err2 := json.Unmarshal(bytes, msg2); err2 == nil {
|
||||
err = nil
|
||||
msg.Id = msg2.Id
|
||||
msg.Method = msg2.Method
|
||||
msg.Error = msg2.Error.Message
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
r.err = errors.WithStack(err)
|
||||
n.err(r.err)
|
||||
} else if len(msg.Error.Message) > 0 {
|
||||
r.err = errors.WithStack(errors.Newf("%d: %s", msg.Error.Code, msg.Error.Message))
|
||||
} else {
|
||||
r.data = bytes
|
||||
}
|
||||
|
||||
if len(msg.Method) > 0 {
|
||||
n.pushHandlersMu.RLock()
|
||||
handlers := n.pushHandlers[msg.Method]
|
||||
n.pushHandlersMu.RUnlock()
|
||||
|
||||
for _, handler := range handlers {
|
||||
select {
|
||||
case handler <- r:
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
n.handlersMu.RLock()
|
||||
c, ok := n.handlers[msg.Id]
|
||||
n.handlersMu.RUnlock()
|
||||
if ok {
|
||||
c <- r
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// listenPush returns a channel of messages matching the method.
|
||||
//func (n *Node) listenPush(method string) <-chan []byte {
|
||||
// c := make(chan []byte, 1)
|
||||
// n.pushHandlersMu.Lock()
|
||||
// defer n.pushHandlersMu.Unlock()
|
||||
// n.pushHandlers[method] = append(n.pushHandlers[method], c)
|
||||
// return c
|
||||
//}
|
||||
|
||||
// request makes a request to the server and unmarshals the response into v.
|
||||
func (n *Node) request(method string, params []string, v interface{}) error {
|
||||
msg := struct {
|
||||
Id uint32 `json:"id"`
|
||||
Method string `json:"method"`
|
||||
Params []string `json:"params"`
|
||||
}{
|
||||
Id: n.nextId.Load(),
|
||||
Method: method,
|
||||
Params: params,
|
||||
}
|
||||
n.nextId.Inc()
|
||||
|
||||
bytes, err := json.Marshal(msg)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
bytes = append(bytes, delimiter)
|
||||
|
||||
c := make(chan response, 1)
|
||||
|
||||
n.handlersMu.Lock()
|
||||
n.handlers[msg.Id] = c
|
||||
n.handlersMu.Unlock()
|
||||
|
||||
err = n.transport.Send(bytes)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
var r response
|
||||
select {
|
||||
case <-n.grp.Ch():
|
||||
return nil
|
||||
case r = <-c:
|
||||
case <-time.After(n.timeout):
|
||||
r = response{err: ErrTimeout}
|
||||
}
|
||||
|
||||
n.handlersMu.Lock()
|
||||
delete(n.handlers, msg.Id)
|
||||
n.handlersMu.Unlock()
|
||||
|
||||
if r.err != nil {
|
||||
return errors.WithStack(r.err)
|
||||
}
|
||||
|
||||
return errors.WithStack(json.Unmarshal(r.data, v))
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package electrum
|
||||
|
||||
// copied from https://github.com/d4l3k/go-electrum
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/v3/extras/stop"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type TCPTransport struct {
|
||||
conn net.Conn
|
||||
responses chan []byte
|
||||
errors chan error
|
||||
grp *stop.Group
|
||||
}
|
||||
|
||||
func NewTransport(addr string, config *tls.Config) (*TCPTransport, error) {
|
||||
var conn net.Conn
|
||||
var err error
|
||||
|
||||
timeout := 5 * time.Second
|
||||
if config != nil {
|
||||
conn, err = tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", addr, config)
|
||||
} else {
|
||||
conn, err = net.DialTimeout("tcp", addr, timeout)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
t := &TCPTransport{
|
||||
conn: conn,
|
||||
responses: make(chan []byte),
|
||||
errors: make(chan error),
|
||||
grp: stop.New(),
|
||||
}
|
||||
|
||||
t.grp.Add(1)
|
||||
go func() {
|
||||
defer t.grp.Done()
|
||||
<-t.grp.Ch()
|
||||
t.close()
|
||||
}()
|
||||
|
||||
t.grp.Add(1)
|
||||
go func() {
|
||||
defer t.grp.Done()
|
||||
t.listen()
|
||||
}()
|
||||
|
||||
err = t.test()
|
||||
if err != nil {
|
||||
t.grp.StopAndWait()
|
||||
return nil, errors.WithMessage(err, addr)
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
const delimiter = byte('\n')
|
||||
|
||||
func (t *TCPTransport) Send(body []byte) error {
|
||||
log.Debugf("%s <- %s", t.conn.RemoteAddr(), body)
|
||||
_, err := t.conn.Write(body)
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *TCPTransport) Responses() <-chan []byte { return t.responses }
|
||||
func (t *TCPTransport) Errors() <-chan error { return t.errors }
|
||||
func (t *TCPTransport) Shutdown() { t.grp.StopAndWait() }
|
||||
|
||||
func (t *TCPTransport) listen() {
|
||||
reader := bufio.NewReader(t.conn)
|
||||
for {
|
||||
line, err := reader.ReadBytes(delimiter)
|
||||
if err != nil {
|
||||
t.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("%s -> %s", t.conn.RemoteAddr(), line)
|
||||
|
||||
t.responses <- line
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TCPTransport) error(err error) {
|
||||
select {
|
||||
case t.errors <- err:
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TCPTransport) test() error {
|
||||
err := t.Send([]byte(`{"id":1,"method":"server.version"}` + "\n"))
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
var data []byte
|
||||
select {
|
||||
case data = <-t.Responses():
|
||||
case <-time.Tick(1 * time.Second):
|
||||
return errors.WithStack(ErrTimeout)
|
||||
}
|
||||
|
||||
var response struct {
|
||||
Error struct {
|
||||
Message string `json:"message"`
|
||||
} `json:"error"`
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &response)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
if response.Error.Message != "" {
|
||||
return errors.WithStack(errors.New(response.Error.Message))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *TCPTransport) close() {
|
||||
err := t.conn.Close()
|
||||
if err != nil {
|
||||
t.error(err)
|
||||
}
|
||||
}
|
||||
@@ -1,277 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/util"
|
||||
"github.com/lbryio/lbry.go/extras/validator"
|
||||
v "github.com/lbryio/ozzo-validation"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// ResponseHeaders are returned with each response
|
||||
var ResponseHeaders map[string]string
|
||||
|
||||
// Log allows logging of events and errors
|
||||
var Log = func(*http.Request, *Response, error) {}
|
||||
|
||||
// TraceEnabled Attaches a trace field to the JSON response when enabled.
|
||||
var TraceEnabled = false
|
||||
|
||||
// StatusError represents an error with an associated HTTP status code.
|
||||
type StatusError struct {
|
||||
Status int
|
||||
Err error
|
||||
}
|
||||
|
||||
func (se StatusError) Error() string { return se.Err.Error() }
|
||||
|
||||
// Response is returned by API handlers
|
||||
type Response struct {
|
||||
Status int
|
||||
Data interface{}
|
||||
RedirectURL string
|
||||
Error error
|
||||
}
|
||||
|
||||
// Handler handles API requests
|
||||
type Handler func(r *http.Request) Response
|
||||
|
||||
func (h Handler) callHandlerSafely(r *http.Request) (rsp Response) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err, ok := r.(error)
|
||||
if !ok {
|
||||
err = errors.Err("%v", r)
|
||||
}
|
||||
rsp = Response{Error: errors.Wrap(err, 2)}
|
||||
}
|
||||
}()
|
||||
|
||||
return h(r)
|
||||
}
|
||||
|
||||
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
// Set header settings
|
||||
if ResponseHeaders != nil {
|
||||
//Multiple readers, no writers is okay
|
||||
for key, value := range ResponseHeaders {
|
||||
w.Header().Set(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Stop here if its a preflighted OPTIONS request
|
||||
if r.Method == "OPTIONS" {
|
||||
return
|
||||
}
|
||||
|
||||
rsp := h.callHandlerSafely(r)
|
||||
|
||||
if rsp.Status == 0 {
|
||||
if rsp.Error != nil {
|
||||
ogErr := errors.Unwrap(rsp.Error)
|
||||
if statusError, ok := ogErr.(StatusError); ok {
|
||||
rsp.Status = statusError.Status
|
||||
} else {
|
||||
rsp.Status = http.StatusInternalServerError
|
||||
}
|
||||
} else if rsp.RedirectURL != "" {
|
||||
rsp.Status = http.StatusFound
|
||||
} else {
|
||||
rsp.Status = http.StatusOK
|
||||
}
|
||||
}
|
||||
|
||||
success := rsp.Status < http.StatusBadRequest
|
||||
if success {
|
||||
Log(r, &rsp, nil)
|
||||
} else {
|
||||
Log(r, &rsp, rsp.Error)
|
||||
}
|
||||
|
||||
// redirect
|
||||
if rsp.Status >= http.StatusMultipleChoices && rsp.Status < http.StatusBadRequest {
|
||||
http.Redirect(w, r, rsp.RedirectURL, rsp.Status)
|
||||
return
|
||||
} else if rsp.RedirectURL != "" {
|
||||
Log(r, &rsp, errors.Base(
|
||||
"status code %d does not indicate a redirect, but RedirectURL is non-empty '%s'",
|
||||
rsp.Status, rsp.RedirectURL,
|
||||
))
|
||||
}
|
||||
|
||||
var errorString *string
|
||||
if rsp.Error != nil {
|
||||
errorStringRaw := rsp.Error.Error()
|
||||
errorString = &errorStringRaw
|
||||
}
|
||||
|
||||
var trace []string
|
||||
if TraceEnabled && errors.HasTrace(rsp.Error) {
|
||||
trace = strings.Split(errors.Trace(rsp.Error), "\n")
|
||||
for index, element := range trace {
|
||||
if strings.HasPrefix(element, "\t") {
|
||||
trace[index] = strings.Replace(element, "\t", " ", 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// http://choly.ca/post/go-json-marshalling/
|
||||
jsonResponse, err := json.MarshalIndent(&struct {
|
||||
Success bool `json:"success"`
|
||||
Error *string `json:"error"`
|
||||
Data interface{} `json:"data"`
|
||||
Trace []string `json:"_trace,omitempty"`
|
||||
}{
|
||||
Success: success,
|
||||
Error: errorString,
|
||||
Data: rsp.Data,
|
||||
Trace: trace,
|
||||
}, "", " ")
|
||||
if err != nil {
|
||||
Log(r, &rsp, errors.Prefix("Error encoding JSON response: ", err))
|
||||
}
|
||||
|
||||
w.WriteHeader(rsp.Status)
|
||||
w.Write(jsonResponse)
|
||||
}
|
||||
|
||||
// IgnoredFormFields are ignored by FormValues() when checking for extraneous fields
|
||||
var IgnoredFormFields []string
|
||||
|
||||
func FormValues(r *http.Request, params interface{}, validationRules []*v.FieldRules) error {
|
||||
ref := reflect.ValueOf(params)
|
||||
if !ref.IsValid() || ref.Kind() != reflect.Ptr || ref.Elem().Kind() != reflect.Struct {
|
||||
return errors.Err("'params' must be a pointer to a struct")
|
||||
}
|
||||
|
||||
structType := ref.Elem().Type()
|
||||
structValue := ref.Elem()
|
||||
fields := map[string]bool{}
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
name := structType.Field(i).Name
|
||||
underscoredName := util.Underscore(name)
|
||||
value := strings.TrimSpace(r.FormValue(underscoredName))
|
||||
|
||||
// if param is not set at all, continue
|
||||
// comes after call to r.FormValue so form values get parsed internally (if they arent already)
|
||||
if len(r.Form[underscoredName]) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
fields[underscoredName] = true
|
||||
isPtr := false
|
||||
var finalValue reflect.Value
|
||||
|
||||
structField := structValue.FieldByName(name)
|
||||
structFieldKind := structField.Kind()
|
||||
if structFieldKind == reflect.Ptr {
|
||||
isPtr = true
|
||||
structFieldKind = structField.Type().Elem().Kind()
|
||||
}
|
||||
|
||||
switch structFieldKind {
|
||||
case reflect.String:
|
||||
finalValue = reflect.ValueOf(value)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
castVal, err := cast.ToInt64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be an integer", underscoredName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Int:
|
||||
finalValue = reflect.ValueOf(int(castVal))
|
||||
case reflect.Int8:
|
||||
finalValue = reflect.ValueOf(int8(castVal))
|
||||
case reflect.Int16:
|
||||
finalValue = reflect.ValueOf(int16(castVal))
|
||||
case reflect.Int32:
|
||||
finalValue = reflect.ValueOf(int32(castVal))
|
||||
case reflect.Int64:
|
||||
finalValue = reflect.ValueOf(castVal)
|
||||
}
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
castVal, err := cast.ToUint64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be an unsigned integer", underscoredName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Uint:
|
||||
finalValue = reflect.ValueOf(uint(castVal))
|
||||
case reflect.Uint8:
|
||||
finalValue = reflect.ValueOf(uint8(castVal))
|
||||
case reflect.Uint16:
|
||||
finalValue = reflect.ValueOf(uint16(castVal))
|
||||
case reflect.Uint32:
|
||||
finalValue = reflect.ValueOf(uint32(castVal))
|
||||
case reflect.Uint64:
|
||||
finalValue = reflect.ValueOf(castVal)
|
||||
}
|
||||
case reflect.Bool:
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
if !validator.IsBoolString(value) {
|
||||
return errors.Err("%s: must be one of the following values: %s",
|
||||
underscoredName, strings.Join(validator.GetBoolStringValues(), ", "))
|
||||
}
|
||||
finalValue = reflect.ValueOf(validator.IsTruthy(value))
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
castVal, err := cast.ToFloat64E(value)
|
||||
if err != nil {
|
||||
return errors.Err("%s: must be a floating point number", underscoredName)
|
||||
}
|
||||
switch structFieldKind {
|
||||
case reflect.Float32:
|
||||
finalValue = reflect.ValueOf(float32(castVal))
|
||||
case reflect.Float64:
|
||||
finalValue = reflect.ValueOf(float64(castVal))
|
||||
}
|
||||
default:
|
||||
return errors.Err("field %s is an unsupported type", name)
|
||||
}
|
||||
|
||||
if isPtr {
|
||||
if structField.IsNil() {
|
||||
structField.Set(reflect.New(structField.Type().Elem()))
|
||||
}
|
||||
structField.Elem().Set(finalValue)
|
||||
} else {
|
||||
structField.Set(finalValue)
|
||||
}
|
||||
}
|
||||
|
||||
var extraParams []string
|
||||
for k := range r.Form {
|
||||
if _, ok := fields[k]; !ok && !util.InSlice(k, IgnoredFormFields) {
|
||||
extraParams = append(extraParams, k)
|
||||
}
|
||||
}
|
||||
if len(extraParams) > 0 {
|
||||
return errors.Err("Extraneous params: " + strings.Join(extraParams, ", "))
|
||||
}
|
||||
|
||||
if len(validationRules) > 0 {
|
||||
validationErr := v.ValidateStruct(params, validationRules...)
|
||||
if validationErr != nil {
|
||||
return errors.Err(validationErr)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"golang.org/x/crypto/sha3"
|
||||
)
|
||||
|
||||
// RandString returns a random alphanumeric string of a given length
|
||||
func RandString(length int) string {
|
||||
buf := make([]byte, length)
|
||||
_, err := rand.Reader.Read(buf)
|
||||
if err != nil {
|
||||
panic(errors.Err(err))
|
||||
}
|
||||
|
||||
randStr := base58.Encode(buf)[:length]
|
||||
if len(randStr) < length {
|
||||
panic(errors.Err("Could not create random string that is long enough"))
|
||||
}
|
||||
|
||||
return randStr
|
||||
}
|
||||
|
||||
// Int returns a uniform random value in [0, max). It panics if max <= 0.
|
||||
func RandInt64(max int64) int64 {
|
||||
n, err := rand.Int(rand.Reader, big.NewInt(max))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n.Int64()
|
||||
}
|
||||
|
||||
// HashStringSlice returns a hex hash of a slice of strings
|
||||
func HashStringSlice(data []string) string {
|
||||
return hex.EncodeToString(hashStringSliceRaw(data))
|
||||
}
|
||||
|
||||
func hashStringSliceRaw(data []string) []byte {
|
||||
sort.Strings(data)
|
||||
hash := sha3.Sum256([]byte(strings.Join(data, "")))
|
||||
return hash[:]
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
# errors
|
||||
|
||||
Better error handling. Marries [go-errors/errors](https://github.com/go-errors/errors) to [pkg/errors](https://github.com/pkg/errors), and
|
||||
adds a little bit of our own magic sauce.
|
||||
@@ -1,110 +0,0 @@
|
||||
package errors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-errors/errors"
|
||||
)
|
||||
|
||||
// interop with pkg/errors
|
||||
type causer interface {
|
||||
Cause() error
|
||||
}
|
||||
|
||||
// Err intelligently creates/handles errors, while preserving the stack trace.
|
||||
// It works with errors from github.com/pkg/errors too.
|
||||
func Err(err interface{}, fmtParams ...interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := err.(causer); ok {
|
||||
err = fmt.Errorf("%+v", err)
|
||||
} else if errString, ok := err.(string); ok && len(fmtParams) > 0 {
|
||||
err = fmt.Errorf(errString, fmtParams...)
|
||||
}
|
||||
|
||||
return errors.Wrap(err, 1)
|
||||
}
|
||||
|
||||
// Wrap calls errors.Wrap, in case you want to skip a different amount
|
||||
func Wrap(err interface{}, skip int) *errors.Error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if _, ok := err.(causer); ok {
|
||||
err = fmt.Errorf("%+v", err)
|
||||
}
|
||||
|
||||
return errors.Wrap(err, skip+1)
|
||||
}
|
||||
|
||||
// Unwrap returns the original error that was wrapped
|
||||
func Unwrap(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
deeper := true
|
||||
for deeper {
|
||||
deeper = false
|
||||
if e, ok := err.(*errors.Error); ok {
|
||||
err = e.Err
|
||||
deeper = true
|
||||
}
|
||||
if c, ok := err.(causer); ok {
|
||||
err = c.Cause()
|
||||
deeper = true
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Is compares two wrapped errors to determine if the underlying errors are the same
|
||||
// It also interops with errors from pkg/errors
|
||||
func Is(e error, original error) bool {
|
||||
if c, ok := e.(causer); ok {
|
||||
e = c.Cause()
|
||||
}
|
||||
if c, ok := original.(causer); ok {
|
||||
original = c.Cause()
|
||||
}
|
||||
return errors.Is(e, original)
|
||||
}
|
||||
|
||||
// Prefix prefixes the message of the error with the given string
|
||||
func Prefix(prefix string, err interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errors.WrapPrefix(Err(err), prefix, 0)
|
||||
}
|
||||
|
||||
// Trace returns the stack trace
|
||||
func Trace(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
return string(Err(err).(*errors.Error).Stack())
|
||||
}
|
||||
|
||||
// FullTrace returns the error type, message, and stack trace
|
||||
func FullTrace(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
return Err(err).(*errors.Error).ErrorStack()
|
||||
}
|
||||
|
||||
// Base returns a simple error with no stack trace attached
|
||||
func Base(format string, a ...interface{}) error {
|
||||
return fmt.Errorf(format, a...)
|
||||
}
|
||||
|
||||
// HasTrace checks if error has a trace attached
|
||||
func HasTrace(err error) bool {
|
||||
_, ok := err.(*errors.Error)
|
||||
return ok
|
||||
}
|
||||
@@ -1,485 +0,0 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"github.com/shopspring/decimal"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/ybbus/jsonrpc"
|
||||
)
|
||||
|
||||
const DefaultPort = 5279
|
||||
|
||||
type Client struct {
|
||||
conn jsonrpc.RPCClient
|
||||
address string
|
||||
}
|
||||
|
||||
func NewClient(address string) *Client {
|
||||
d := Client{}
|
||||
|
||||
if address == "" {
|
||||
address = "http://localhost:" + strconv.Itoa(DefaultPort)
|
||||
}
|
||||
|
||||
d.conn = jsonrpc.NewClient(address)
|
||||
d.address = address
|
||||
|
||||
return &d
|
||||
}
|
||||
|
||||
func NewClientAndWait(address string) *Client {
|
||||
d := NewClient(address)
|
||||
for {
|
||||
_, err := d.WalletBalance()
|
||||
if err == nil {
|
||||
return d
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func decode(data interface{}, targetStruct interface{}) error {
|
||||
config := &mapstructure.DecoderConfig{
|
||||
Metadata: nil,
|
||||
Result: targetStruct,
|
||||
TagName: "json",
|
||||
//WeaklyTypedInput: true,
|
||||
DecodeHook: fixDecodeProto,
|
||||
}
|
||||
|
||||
decoder, err := mapstructure.NewDecoder(config)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, 0)
|
||||
}
|
||||
|
||||
err = decoder.Decode(data)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, 0)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func decodeNumber(data interface{}) (decimal.Decimal, error) {
|
||||
var number string
|
||||
|
||||
switch d := data.(type) {
|
||||
case json.Number:
|
||||
number = d.String()
|
||||
case string:
|
||||
number = d
|
||||
default:
|
||||
return decimal.Decimal{}, errors.Err("unexpected number type")
|
||||
}
|
||||
|
||||
dec, err := decimal.NewFromString(number)
|
||||
if err != nil {
|
||||
return decimal.Decimal{}, errors.Wrap(err, 0)
|
||||
}
|
||||
|
||||
return dec, nil
|
||||
}
|
||||
|
||||
func debugParams(params map[string]interface{}) string {
|
||||
var s []string
|
||||
for k, v := range params {
|
||||
r := reflect.ValueOf(v)
|
||||
if r.Kind() == reflect.Ptr {
|
||||
if r.IsNil() {
|
||||
continue
|
||||
}
|
||||
v = r.Elem().Interface()
|
||||
}
|
||||
s = append(s, fmt.Sprintf("%s=%+v", k, v))
|
||||
}
|
||||
sort.Strings(s)
|
||||
return strings.Join(s, " ")
|
||||
}
|
||||
|
||||
func (d *Client) callNoDecode(command string, params map[string]interface{}) (interface{}, error) {
|
||||
log.Debugln("jsonrpc: " + command + " " + debugParams(params))
|
||||
r, err := d.conn.Call(command, params)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
}
|
||||
|
||||
if r.Error != nil {
|
||||
return nil, errors.Err("Error in daemon: " + r.Error.Message)
|
||||
}
|
||||
|
||||
return r.Result, nil
|
||||
}
|
||||
|
||||
func (d *Client) call(response interface{}, command string, params map[string]interface{}) error {
|
||||
result, err := d.callNoDecode(command, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return decode(result, response)
|
||||
}
|
||||
|
||||
func (d *Client) SetRPCTimeout(timeout time.Duration) {
|
||||
d.conn = jsonrpc.NewClientWithOpts(d.address, &jsonrpc.RPCClientOpts{
|
||||
HTTPClient: &http.Client{Timeout: timeout},
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Commands() (*CommandsResponse, error) {
|
||||
response := new(CommandsResponse)
|
||||
return response, d.call(response, "commands", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) Status() (*StatusResponse, error) {
|
||||
response := new(StatusResponse)
|
||||
return response, d.call(response, "status", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) WalletBalance() (*WalletBalanceResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_balance", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec, err := decodeNumber(rawResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := WalletBalanceResponse(dec)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (d *Client) WalletList() (*WalletListResponse, error) {
|
||||
response := new(WalletListResponse)
|
||||
return response, d.call(response, "wallet_list", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) UTXOList() (*UTXOListResponse, error) {
|
||||
response := new(UTXOListResponse)
|
||||
return response, d.call(response, "utxo_list", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) Version() (*VersionResponse, error) {
|
||||
response := new(VersionResponse)
|
||||
return response, d.call(response, "version", map[string]interface{}{})
|
||||
}
|
||||
|
||||
func (d *Client) Get(url string, filename *string, timeout *uint) (*GetResponse, error) {
|
||||
response := new(GetResponse)
|
||||
return response, d.call(response, "get", map[string]interface{}{
|
||||
"uri": url,
|
||||
"file_name": filename,
|
||||
"timeout": timeout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ClaimList(name string) (*ClaimListResponse, error) {
|
||||
response := new(ClaimListResponse)
|
||||
return response, d.call(response, "claim_list", map[string]interface{}{
|
||||
"name": name,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ClaimShow(claimID *string, txid *string, nout *uint) (*ClaimShowResponse, error) {
|
||||
response := new(ClaimShowResponse)
|
||||
return response, d.call(response, "claim_show", map[string]interface{}{
|
||||
"claim_id": claimID,
|
||||
"txid": txid,
|
||||
"nout": nout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) PeerList(blobHash string, timeout *uint) (*PeerListResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("peer_list", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"timeout": timeout,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
castResponse, ok := rawResponse.([]interface{})
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid peer_list response")
|
||||
}
|
||||
|
||||
peers := []PeerListResponsePeer{}
|
||||
for _, peer := range castResponse {
|
||||
t, ok := peer.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid peer_list response")
|
||||
}
|
||||
|
||||
if len(t) != 3 {
|
||||
return nil, errors.Err("invalid triplet in peer_list response")
|
||||
}
|
||||
|
||||
ip, ok := t["host"].(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid ip in peer_list response")
|
||||
}
|
||||
port, ok := t["port"].(json.Number)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid port in peer_list response")
|
||||
}
|
||||
nodeid, ok := t["node_id"].(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("invalid nodeid in peer_list response")
|
||||
}
|
||||
|
||||
portNum, err := port.Int64()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
} else if portNum < 0 {
|
||||
return nil, errors.Err("invalid port in peer_list response")
|
||||
}
|
||||
|
||||
peers = append(peers, PeerListResponsePeer{
|
||||
IP: ip,
|
||||
Port: uint(portNum),
|
||||
NodeId: nodeid,
|
||||
})
|
||||
}
|
||||
|
||||
response := PeerListResponse(peers)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (d *Client) BlobGet(blobHash string, encoding *string, timeout *uint) (*BlobGetResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("blob_get", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"timeout": timeout,
|
||||
"encoding": encoding,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := rawResponse.(string); ok {
|
||||
return nil, nil // blob was downloaded, nothing to return
|
||||
}
|
||||
|
||||
response := new(BlobGetResponse)
|
||||
return response, decode(rawResponse, response)
|
||||
}
|
||||
|
||||
func (d *Client) StreamAvailability(url string, search_timeout *uint64, blob_timeout *uint64) (*StreamAvailabilityResponse, error) {
|
||||
response := new(StreamAvailabilityResponse)
|
||||
return response, d.call(response, "stream_availability", map[string]interface{}{
|
||||
"uri": url,
|
||||
"search_timeout": search_timeout,
|
||||
"blob_timeout": blob_timeout,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) StreamCostEstimate(url string, size *uint64) (*StreamCostEstimateResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("stream_cost_estimate", map[string]interface{}{
|
||||
"uri": url,
|
||||
"size": size,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dec, err := decodeNumber(rawResponse)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
response := StreamCostEstimateResponse(dec)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
type FileListOptions struct {
|
||||
SDHash *string
|
||||
StreamHash *string
|
||||
FileName *string
|
||||
ClaimID *string
|
||||
Outpoint *string
|
||||
RowID *string
|
||||
Name *string
|
||||
}
|
||||
|
||||
func (d *Client) FileList(options FileListOptions) (*FileListResponse, error) {
|
||||
response := new(FileListResponse)
|
||||
return response, d.call(response, "file_list", map[string]interface{}{
|
||||
"sd_hash": options.SDHash,
|
||||
"stream_hash": options.StreamHash,
|
||||
"file_name": options.FileName,
|
||||
"claim_id": options.ClaimID,
|
||||
"outpoint": options.Outpoint,
|
||||
"rowid": options.RowID,
|
||||
"name": options.Name,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) Resolve(url string) (*ResolveResponse, error) {
|
||||
response := new(ResolveResponse)
|
||||
return response, d.call(response, "resolve", map[string]interface{}{
|
||||
"uri": url,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ChannelNew(name string, amount float64) (*ChannelNewResponse, error) {
|
||||
response := new(ChannelNewResponse)
|
||||
return response, d.call(response, "channel_new", map[string]interface{}{
|
||||
"channel_name": name,
|
||||
"amount": amount,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) ChannelList() (*ChannelListResponse, error) {
|
||||
response := new(ChannelListResponse)
|
||||
return response, d.call(response, "channel_list", map[string]interface{}{})
|
||||
}
|
||||
|
||||
type PublishOptions struct {
|
||||
Fee *Fee
|
||||
Title *string
|
||||
Description *string
|
||||
Author *string
|
||||
Language *string
|
||||
License *string
|
||||
LicenseURL *string
|
||||
Thumbnail *string
|
||||
Preview *string
|
||||
NSFW *bool
|
||||
ChannelName *string
|
||||
ChannelID *string
|
||||
ClaimAddress *string
|
||||
ChangeAddress *string
|
||||
}
|
||||
|
||||
func (d *Client) Publish(name, filePath string, bid float64, options PublishOptions) (*PublishResponse, error) {
|
||||
response := new(PublishResponse)
|
||||
return response, d.call(response, "publish", map[string]interface{}{
|
||||
"name": name,
|
||||
"file_path": filePath,
|
||||
"bid": bid,
|
||||
"fee": options.Fee,
|
||||
"title": options.Title,
|
||||
"description": options.Description,
|
||||
"author": options.Author,
|
||||
"language": options.Language,
|
||||
"license": options.License,
|
||||
"license_url": options.LicenseURL,
|
||||
"thumbnail": options.Thumbnail,
|
||||
"preview": options.Preview,
|
||||
"nsfw": options.NSFW,
|
||||
"channel_name": options.ChannelName,
|
||||
"channel_id": options.ChannelID,
|
||||
"claim_address": options.ClaimAddress,
|
||||
"change_address": options.ChangeAddress,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) BlobAnnounce(blobHash, sdHash, streamHash *string) (*BlobAnnounceResponse, error) {
|
||||
response := new(BlobAnnounceResponse)
|
||||
return response, d.call(response, "blob_announce", map[string]interface{}{
|
||||
"blob_hash": blobHash,
|
||||
"stream_hash": streamHash,
|
||||
"sd_hash": sdHash,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) WalletPrefillAddresses(numAddresses int, amount decimal.Decimal, broadcast bool) (*WalletPrefillAddressesResponse, error) {
|
||||
if numAddresses < 1 {
|
||||
return nil, errors.Err("must create at least 1 address")
|
||||
}
|
||||
response := new(WalletPrefillAddressesResponse)
|
||||
return response, d.call(response, "wallet_prefill_addresses", map[string]interface{}{
|
||||
"num_addresses": numAddresses,
|
||||
"amount": amount,
|
||||
"no_broadcast": !broadcast,
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Client) WalletNewAddress() (*WalletNewAddressResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_new_address", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address, ok := rawResponse.(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("unexpected response")
|
||||
}
|
||||
|
||||
response := WalletNewAddressResponse(address)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (d *Client) WalletUnusedAddress() (*WalletUnusedAddressResponse, error) {
|
||||
rawResponse, err := d.callNoDecode("wallet_unused_address", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
address, ok := rawResponse.(string)
|
||||
if !ok {
|
||||
return nil, errors.Err("unexpected response")
|
||||
}
|
||||
|
||||
response := WalletUnusedAddressResponse(address)
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (d *Client) NumClaimsInChannel(url string) (uint64, error) {
|
||||
response := new(NumClaimsInChannelResponse)
|
||||
err := d.call(response, "claim_list_by_channel", map[string]interface{}{
|
||||
"uri": url,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
} else if response == nil {
|
||||
return 0, errors.Err("no response")
|
||||
}
|
||||
|
||||
channel, ok := (*response)[url]
|
||||
if !ok {
|
||||
return 0, errors.Err("url not in response")
|
||||
}
|
||||
if channel.Error != "" {
|
||||
if strings.Contains(channel.Error, "cannot be resolved") {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, errors.Err(channel.Error)
|
||||
}
|
||||
return channel.ClaimsInChannel, nil
|
||||
}
|
||||
|
||||
func (d *Client) ClaimListMine() (*ClaimListMineResponse, error) {
|
||||
response := new(ClaimListMineResponse)
|
||||
err := d.call(response, "claim_list_mine", map[string]interface{}{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if response == nil {
|
||||
return nil, errors.Err("no response")
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (d *Client) ClaimAbandon(txID string, nOut int) (*ClaimAbandonResponse, error) {
|
||||
response := new(ClaimAbandonResponse)
|
||||
err := d.call(response, "claim_abandon", map[string]interface{}{
|
||||
"txid": txID,
|
||||
"nout": nOut,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if response == nil {
|
||||
return nil, errors.Err("no response")
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStatus(t *testing.T) {
|
||||
}
|
||||
@@ -1,376 +0,0 @@
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
lbryschema "github.com/lbryio/types/v1/go"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
CurrencyLBC = Currency("LBC")
|
||||
CurrencyUSD = Currency("USD")
|
||||
CurrencyBTC = Currency("BTC")
|
||||
)
|
||||
|
||||
type Fee struct {
|
||||
Currency Currency `json:"currency"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Address *string `json:"address"`
|
||||
}
|
||||
|
||||
type Support struct {
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Nout int `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type Claim struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
BlocksToExpiration int `json:"blocks_to_expiration"`
|
||||
Category string `json:"category"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
ClaimSequence int `json:"claim_sequence"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
DecodedClaim bool `json:"decoded_claim"`
|
||||
Depth int `json:"depth"`
|
||||
EffectiveAmount decimal.Decimal `json:"effective_amount"`
|
||||
ExpirationHeight int `json:"expiration_height"`
|
||||
Expired bool `json:"expired"`
|
||||
Height int `json:"height"`
|
||||
Hex string `json:"hex"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Name string `json:"name"`
|
||||
Nout int `json:"nout"`
|
||||
PermanentUrl string `json:"permanent_url"`
|
||||
Supports []Support `json:"supports"`
|
||||
Txid string `json:"txid"`
|
||||
ValidAtHeight int `json:"valid_at_height"`
|
||||
Value lbryschema.Claim `json:"value"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
ChannelName *string `json:"channel_name,omitempty"`
|
||||
HasSignature *bool `json:"has_signature,omitempty"`
|
||||
SignatureIsValid *bool `json:"signature_is_valid,omitempty"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Completed bool `json:"completed"`
|
||||
DownloadDirectory string `json:"download_directory"`
|
||||
DownloadPath string `json:"download_path"`
|
||||
FileName string `json:"file_name"`
|
||||
Key string `json:"key"`
|
||||
Message string `json:"message"`
|
||||
Metadata *lbryschema.Claim `json:"metadata"`
|
||||
MimeType string `json:"mime_type"`
|
||||
Name string `json:"name"`
|
||||
Outpoint string `json:"outpoint"`
|
||||
PointsPaid decimal.Decimal `json:"points_paid"`
|
||||
SdHash string `json:"sd_hash"`
|
||||
Stopped bool `json:"stopped"`
|
||||
StreamHash string `json:"stream_hash"`
|
||||
StreamName string `json:"stream_name"`
|
||||
SuggestedFileName string `json:"suggested_file_name"`
|
||||
TotalBytes uint64 `json:"total_bytes"`
|
||||
WrittenBytes uint64 `json:"written_bytes"`
|
||||
ChannelName *string `json:"channel_name,omitempty"`
|
||||
HasSignature *bool `json:"has_signature,omitempty"`
|
||||
SignatureIsValid *bool `json:"signature_is_valid,omitempty"`
|
||||
}
|
||||
|
||||
func getEnumVal(enum map[string]int32, data interface{}) (int32, error) {
|
||||
s, ok := data.(string)
|
||||
if !ok {
|
||||
return 0, errors.Err("expected a string")
|
||||
}
|
||||
val, ok := enum[s]
|
||||
if !ok {
|
||||
return 0, errors.Err("invalid enum key")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func fixDecodeProto(src, dest reflect.Type, data interface{}) (interface{}, error) {
|
||||
switch dest {
|
||||
case reflect.TypeOf(uint64(0)):
|
||||
if n, ok := data.(json.Number); ok {
|
||||
val, err := n.Int64()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
} else if val < 0 {
|
||||
return nil, errors.Err("must be unsigned int")
|
||||
}
|
||||
return uint64(val), nil
|
||||
}
|
||||
case reflect.TypeOf([]byte{}):
|
||||
if s, ok := data.(string); ok {
|
||||
return []byte(s), nil
|
||||
}
|
||||
|
||||
case reflect.TypeOf(decimal.Decimal{}):
|
||||
if n, ok := data.(json.Number); ok {
|
||||
val, err := n.Float64()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
}
|
||||
return decimal.NewFromFloat(val), nil
|
||||
} else if s, ok := data.(string); ok {
|
||||
d, err := decimal.NewFromString(s)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, 0)
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
||||
case reflect.TypeOf(lbryschema.Metadata_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Metadata_Version_value, data)
|
||||
return lbryschema.Metadata_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Metadata_Language(0)):
|
||||
val, err := getEnumVal(lbryschema.Metadata_Language_value, data)
|
||||
return lbryschema.Metadata_Language(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Stream_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Stream_Version_value, data)
|
||||
return lbryschema.Stream_Version(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Claim_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Claim_Version_value, data)
|
||||
return lbryschema.Claim_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Claim_ClaimType(0)):
|
||||
val, err := getEnumVal(lbryschema.Claim_ClaimType_value, data)
|
||||
return lbryschema.Claim_ClaimType(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Fee_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Fee_Version_value, data)
|
||||
return lbryschema.Fee_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Fee_Currency(0)):
|
||||
val, err := getEnumVal(lbryschema.Fee_Currency_value, data)
|
||||
return lbryschema.Fee_Currency(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Source_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Source_Version_value, data)
|
||||
return lbryschema.Source_Version(val), err
|
||||
case reflect.TypeOf(lbryschema.Source_SourceTypes(0)):
|
||||
val, err := getEnumVal(lbryschema.Source_SourceTypes_value, data)
|
||||
return lbryschema.Source_SourceTypes(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.KeyType(0)):
|
||||
val, err := getEnumVal(lbryschema.KeyType_value, data)
|
||||
return lbryschema.KeyType(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Signature_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Signature_Version_value, data)
|
||||
return lbryschema.Signature_Version(val), err
|
||||
|
||||
case reflect.TypeOf(lbryschema.Certificate_Version(0)):
|
||||
val, err := getEnumVal(lbryschema.Certificate_Version_value, data)
|
||||
return lbryschema.Certificate_Version(val), err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
type CommandsResponse []string
|
||||
|
||||
type WalletBalanceResponse decimal.Decimal
|
||||
|
||||
type VersionResponse struct {
|
||||
Build string `json:"build"`
|
||||
LbrynetVersion string `json:"lbrynet_version"`
|
||||
LbryschemaVersion string `json:"lbryschema_version"`
|
||||
LbryumVersion string `json:"lbryum_version"`
|
||||
OsRelease string `json:"os_release"`
|
||||
OsSystem string `json:"os_system"`
|
||||
Platform string `json:"platform"`
|
||||
Processor string `json:"processor"`
|
||||
PythonVersion string `json:"python_version"`
|
||||
}
|
||||
type StatusResponse struct {
|
||||
BlobManager struct {
|
||||
FinishedBlobs int `json:"finished_blobs"`
|
||||
} `json:"blob_manager"`
|
||||
ConnectionStatus struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
} `json:"connection_status"`
|
||||
Dht struct {
|
||||
NodeID string `json:"node_id"`
|
||||
PeersInRoutingTable int `json:"peers_in_routing_table"`
|
||||
} `json:"dht"`
|
||||
FileManager struct {
|
||||
ManagedFiles int `json:"managed_files"`
|
||||
} `json:"file_manager"`
|
||||
HashAnnouncer struct {
|
||||
AnnounceQueueSize int `json:"announce_queue_size"`
|
||||
} `json:"hash_announcer"`
|
||||
InstallationID string `json:"installation_id"`
|
||||
IsFirstRun bool `json:"is_first_run"`
|
||||
IsRunning bool `json:"is_running"`
|
||||
SkippedComponents []string `json:"skipped_components"`
|
||||
StartupStatus struct {
|
||||
BlobManager bool `json:"blob_manager"`
|
||||
BlockchainHeaders bool `json:"blockchain_headers"`
|
||||
Database bool `json:"database"`
|
||||
Dht bool `json:"dht"`
|
||||
ExchangeRateManager bool `json:"exchange_rate_manager"`
|
||||
FileManager bool `json:"file_manager"`
|
||||
HashAnnouncer bool `json:"hash_announcer"`
|
||||
PaymentRateManager bool `json:"payment_rate_manager"`
|
||||
PeerProtocolServer bool `json:"peer_protocol_server"`
|
||||
RateLimiter bool `json:"rate_limiter"`
|
||||
StreamIdentifier bool `json:"stream_identifier"`
|
||||
Upnp bool `json:"upnp"`
|
||||
Wallet bool `json:"wallet"`
|
||||
} `json:"startup_status"`
|
||||
Wallet struct {
|
||||
BestBlockchain string `json:"best_blockchain"`
|
||||
Blocks int `json:"blocks"`
|
||||
BlocksBehind int `json:"blocks_behind"`
|
||||
IsEncrypted bool `json:"is_encrypted"`
|
||||
} `json:"wallet"`
|
||||
}
|
||||
|
||||
type ClaimListResponse struct {
|
||||
Claims []Claim `json:"claims"`
|
||||
LastTakeoverHeight int `json:"last_takeover_height"`
|
||||
SupportsWithoutClaims []Support `json:"supports_without_claims"`
|
||||
}
|
||||
type ClaimListMineResponse []Claim
|
||||
type ClaimShowResponse Claim
|
||||
type ClaimAbandonResponse struct {
|
||||
Txid string `json:"txid"`
|
||||
Fee float64 `json:"fee"`
|
||||
}
|
||||
|
||||
type PeerListResponsePeer struct {
|
||||
IP string `json:"host"`
|
||||
Port uint `json:"port"`
|
||||
NodeId string `json:"node_id"`
|
||||
}
|
||||
type PeerListResponse []PeerListResponsePeer
|
||||
|
||||
type BlobGetResponse struct {
|
||||
Blobs []struct {
|
||||
BlobHash string `json:"blob_hash,omitempty"`
|
||||
BlobNum int `json:"blob_num"`
|
||||
IV string `json:"iv"`
|
||||
Length int `json:"length"`
|
||||
} `json:"blobs"`
|
||||
Key string `json:"key"`
|
||||
StreamHash string `json:"stream_hash"`
|
||||
StreamName string `json:"stream_name"`
|
||||
StreamType string `json:"stream_type"`
|
||||
SuggestedFileName string `json:"suggested_file_name"`
|
||||
}
|
||||
|
||||
type StreamCostEstimateResponse decimal.Decimal
|
||||
|
||||
type BlobAvailability struct {
|
||||
IsAvailable bool `json:"is_available"`
|
||||
ReachablePeers []string `json:"reachable_peers"`
|
||||
UnReachablePeers []string `json:"unreachable_peers"`
|
||||
}
|
||||
|
||||
type StreamAvailabilityResponse struct {
|
||||
IsAvailable bool `json:"is_available"`
|
||||
DidDecode bool `json:"did_decode"`
|
||||
DidResolve bool `json:"did_resolve"`
|
||||
IsStream bool `json:"is_stream"`
|
||||
NumBlobsInStream uint64 `json:"num_blobs_in_stream"`
|
||||
SDHash string `json:"sd_hash"`
|
||||
SDBlobAvailability BlobAvailability `json:"sd_blob_availability"`
|
||||
HeadBlobHash string `json:"head_blob_hash"`
|
||||
HeadBlobAvailability BlobAvailability `json:"head_blob_availability"`
|
||||
UseUPNP bool `json:"use_upnp"`
|
||||
UPNPRedirectIsSet bool `json:"upnp_redirect_is_set"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type GetResponse File
|
||||
type FileListResponse []File
|
||||
|
||||
type ResolveResponse map[string]ResolveResponseItem
|
||||
type ResolveResponseItem struct {
|
||||
Certificate *Claim `json:"certificate,omitempty"`
|
||||
Claim *Claim `json:"claim,omitempty"`
|
||||
ClaimsInChannel *uint64 `json:"claims_in_channel,omitempty"`
|
||||
Error *string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type ChannelNewResponse struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Fee decimal.Decimal `json:"fee"`
|
||||
Nout int `json:"nout"`
|
||||
Success bool `json:"success"`
|
||||
Tx string `json:"tx"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type ChannelListSingleResponse struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
BlocksToExpiration int `json:"blocks_to_expiration"`
|
||||
CanSign bool `json:"can_sign"`
|
||||
Category string `json:"category"`
|
||||
ClaimID string `json:"claim_id"`
|
||||
Confirmations int `json:"confirmations"`
|
||||
DecodedClaim bool `json:"decoded_claim"`
|
||||
ExpirationHeight int `json:"expiration_height"`
|
||||
Expired bool `json:"expired"`
|
||||
HasSignature bool `json:"has_signature"`
|
||||
Height int `json:"height"`
|
||||
Hex string `json:"hex"`
|
||||
IsPending bool `json:"is_pending"`
|
||||
IsSpent bool `json:"is_spent"`
|
||||
Name string `json:"name"`
|
||||
Nout int `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
Value *lbryschema.Claim `json:"value"`
|
||||
}
|
||||
|
||||
type ChannelListResponse []ChannelListSingleResponse
|
||||
|
||||
type WalletListResponse []string
|
||||
|
||||
type PublishResponse struct {
|
||||
ClaimID string `json:"claim_id"`
|
||||
Fee decimal.Decimal `json:"fee"`
|
||||
Nout int `json:"nout"`
|
||||
Tx string `json:"tx"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type BlobAnnounceResponse bool
|
||||
|
||||
type WalletPrefillAddressesResponse struct {
|
||||
Broadcast bool `json:"broadcast"`
|
||||
Complete bool `json:"complete"`
|
||||
Hex string `json:"hex"`
|
||||
}
|
||||
|
||||
type UTXOListResponse []struct {
|
||||
Address string `json:"address"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Height int `json:"height"`
|
||||
IsClaim bool `json:"is_claim"`
|
||||
IsCoinbase bool `json:"is_coinbase"`
|
||||
IsSupport bool `json:"is_support"`
|
||||
IsUpdate bool `json:"is_update"`
|
||||
Nout int `json:"nout"`
|
||||
Txid string `json:"txid"`
|
||||
}
|
||||
|
||||
type WalletNewAddressResponse string
|
||||
|
||||
type WalletUnusedAddressResponse string
|
||||
|
||||
type NumClaimsInChannelResponse map[string]struct {
|
||||
ClaimsInChannel uint64 `json:"claims_in_channel,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
Copyright for portions of project null-extended are held by *Greg Roseberry, 2014* as part of project null.
|
||||
All other copyright for project null-extended are held by *Patrick O'Brien, 2016*.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,89 +0,0 @@
|
||||
## null-extended [](https://godoc.org/github.com/nullbio/null) [](http://gocover.io/github.com/nullbio/null)
|
||||
|
||||
*Forked from https://github.com/nullbio/null*
|
||||
|
||||
null-extended is a library with reasonable options for dealing with nullable SQL and JSON values
|
||||
|
||||
Types in `null` will only be considered null on null input, and will JSON encode to `null`.
|
||||
|
||||
All types implement `sql.Scanner` and `driver.Valuer`, so you can use this library in place of `sql.NullXXX`. All types also implement: `encoding.TextMarshaler`, `encoding.TextUnmarshaler`, `json.Marshaler`, `json.Unmarshaler` and `sql.Scanner`.
|
||||
|
||||
---
|
||||
|
||||
Install:
|
||||
|
||||
`go get -u "gopkg.in/nullbio/null.v6"`
|
||||
|
||||
### null package
|
||||
|
||||
`import "gopkg.in/nullbio/null.v6"`
|
||||
|
||||
The following are all types supported in this package. All types will marshal to JSON null if Invalid or SQL source data is null.
|
||||
|
||||
#### null.JSON
|
||||
Nullable []byte.
|
||||
|
||||
Will marshal to JSON null if Invalid. []byte{} input will not produce an Invalid JSON, but []byte(nil) will. This should be used for storing raw JSON in the database.
|
||||
|
||||
Also has `null.JSON.Marshal` and `null.JSON.Unmarshal` helpers to marshal and unmarshal foreign objects.
|
||||
|
||||
#### null.Bytes
|
||||
Nullable []byte.
|
||||
|
||||
[]byte{} input will not produce an Invalid Bytes, but []byte(nil) will. This should be used for storing binary data (bytea in PSQL for example) in the database.
|
||||
|
||||
#### null.String
|
||||
Nullable string.
|
||||
|
||||
#### null.Byte
|
||||
Nullable byte.
|
||||
|
||||
#### null.Bool
|
||||
Nullable bool.
|
||||
|
||||
#### null.Time
|
||||
Nullable time.Time
|
||||
|
||||
Marshals to JSON null if SQL source data is null. Uses `time.Time`'s marshaler.
|
||||
|
||||
#### null.Float32
|
||||
Nullable float32.
|
||||
|
||||
#### null.Float64
|
||||
Nullable float64.
|
||||
|
||||
#### null.Int
|
||||
Nullable int.
|
||||
|
||||
#### null.Int8
|
||||
Nullable int8.
|
||||
|
||||
#### null.Int16
|
||||
Nullable int16.
|
||||
|
||||
#### null.Int32
|
||||
Nullable int32.
|
||||
|
||||
#### null.Int64
|
||||
Nullable int64.
|
||||
|
||||
#### null.Uint
|
||||
Nullable uint.
|
||||
|
||||
#### null.Uint8
|
||||
Nullable uint8.
|
||||
|
||||
#### null.Uint16
|
||||
Nullable uint16.
|
||||
|
||||
#### null.Uint32
|
||||
Nullable int32.
|
||||
|
||||
#### null.Int64
|
||||
Nullable uint64.
|
||||
|
||||
### Bugs
|
||||
`json`'s `",omitempty"` struct tag does not work correctly right now. It will never omit a null or empty String. This might be [fixed eventually](https://github.com/golang/go/issues/4357).
|
||||
|
||||
### License
|
||||
BSD
|
||||
@@ -1,133 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Bool is a nullable bool.
|
||||
type Bool struct {
|
||||
Bool bool
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewBool creates a new Bool
|
||||
func NewBool(b bool, valid bool) Bool {
|
||||
return Bool{
|
||||
Bool: b,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// BoolFrom creates a new Bool that will always be valid.
|
||||
func BoolFrom(b bool) Bool {
|
||||
return NewBool(b, true)
|
||||
}
|
||||
|
||||
// BoolFromPtr creates a new Bool that will be null if f is nil.
|
||||
func BoolFromPtr(b *bool) Bool {
|
||||
if b == nil {
|
||||
return NewBool(false, false)
|
||||
}
|
||||
return NewBool(*b, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (b *Bool) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
b.Bool = false
|
||||
b.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &b.Bool); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (b *Bool) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
b.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
str := string(text)
|
||||
switch str {
|
||||
case "true":
|
||||
b.Bool = true
|
||||
case "false":
|
||||
b.Bool = false
|
||||
default:
|
||||
b.Valid = false
|
||||
return errors.New("invalid input:" + str)
|
||||
}
|
||||
b.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (b Bool) MarshalJSON() ([]byte, error) {
|
||||
if !b.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
if !b.Bool {
|
||||
return []byte("false"), nil
|
||||
}
|
||||
return []byte("true"), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (b Bool) MarshalText() ([]byte, error) {
|
||||
if !b.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
if !b.Bool {
|
||||
return []byte("false"), nil
|
||||
}
|
||||
return []byte("true"), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Bool's value and also sets it to be non-null.
|
||||
func (b *Bool) SetValid(v bool) {
|
||||
b.Bool = v
|
||||
b.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Bool's value, or a nil pointer if this Bool is null.
|
||||
func (b Bool) Ptr() *bool {
|
||||
if !b.Valid {
|
||||
return nil
|
||||
}
|
||||
return &b.Bool
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Bools, for future omitempty support (Go 1.4?)
|
||||
func (b Bool) IsNull() bool {
|
||||
return !b.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (b *Bool) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
b.Bool, b.Valid = false, false
|
||||
return nil
|
||||
}
|
||||
b.Valid = true
|
||||
return convert.ConvertAssign(&b.Bool, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (b Bool) Value() (driver.Value, error) {
|
||||
if !b.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return b.Bool, nil
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
boolJSON = []byte(`true`)
|
||||
falseJSON = []byte(`false`)
|
||||
)
|
||||
|
||||
func TestBoolFrom(t *testing.T) {
|
||||
b := BoolFrom(true)
|
||||
assertBool(t, b, "BoolFrom()")
|
||||
|
||||
zero := BoolFrom(false)
|
||||
if !zero.Valid {
|
||||
t.Error("BoolFrom(false)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolFromPtr(t *testing.T) {
|
||||
n := true
|
||||
bptr := &n
|
||||
b := BoolFromPtr(bptr)
|
||||
assertBool(t, b, "BoolFromPtr()")
|
||||
|
||||
null := BoolFromPtr(nil)
|
||||
assertNullBool(t, null, "BoolFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalBool(t *testing.T) {
|
||||
var b Bool
|
||||
err := json.Unmarshal(boolJSON, &b)
|
||||
maybePanic(err)
|
||||
assertBool(t, b, "bool json")
|
||||
|
||||
var null Bool
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullBool(t, null, "null json")
|
||||
|
||||
var badType Bool
|
||||
err = json.Unmarshal(intJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullBool(t, badType, "wrong type json")
|
||||
|
||||
var invalid Bool
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalBool(t *testing.T) {
|
||||
var b Bool
|
||||
err := b.UnmarshalText([]byte("true"))
|
||||
maybePanic(err)
|
||||
assertBool(t, b, "UnmarshalText() bool")
|
||||
|
||||
var zero Bool
|
||||
err = zero.UnmarshalText([]byte("false"))
|
||||
maybePanic(err)
|
||||
assertFalseBool(t, zero, "UnmarshalText() false")
|
||||
|
||||
var blank Bool
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullBool(t, blank, "UnmarshalText() empty bool")
|
||||
|
||||
var invalid Bool
|
||||
err = invalid.UnmarshalText([]byte(":D"))
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullBool(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestMarshalBool(t *testing.T) {
|
||||
b := BoolFrom(true)
|
||||
data, err := json.Marshal(b)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "true", "non-empty json marshal")
|
||||
|
||||
zero := NewBool(false, true)
|
||||
data, err = json.Marshal(zero)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "false", "zero json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewBool(false, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalBoolText(t *testing.T) {
|
||||
b := BoolFrom(true)
|
||||
data, err := b.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "true", "non-empty text marshal")
|
||||
|
||||
zero := NewBool(false, true)
|
||||
data, err = zero.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "false", "zero text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewBool(false, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestBoolPointer(t *testing.T) {
|
||||
b := BoolFrom(true)
|
||||
ptr := b.Ptr()
|
||||
if *ptr != true {
|
||||
t.Errorf("bad %s bool: %#v ≠ %v\n", "pointer", ptr, true)
|
||||
}
|
||||
|
||||
null := NewBool(false, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s bool: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolIsNull(t *testing.T) {
|
||||
b := BoolFrom(true)
|
||||
if b.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewBool(false, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewBool(false, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBoolSetValid(t *testing.T) {
|
||||
change := NewBool(false, false)
|
||||
assertNullBool(t, change, "SetValid()")
|
||||
change.SetValid(true)
|
||||
assertBool(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestBoolScan(t *testing.T) {
|
||||
var b Bool
|
||||
err := b.Scan(true)
|
||||
maybePanic(err)
|
||||
assertBool(t, b, "scanned bool")
|
||||
|
||||
var null Bool
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullBool(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertBool(t *testing.T, b Bool, from string) {
|
||||
if b.Bool != true {
|
||||
t.Errorf("bad %s bool: %v ≠ %v\n", from, b.Bool, true)
|
||||
}
|
||||
if !b.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertFalseBool(t *testing.T, b Bool, from string) {
|
||||
if b.Bool != false {
|
||||
t.Errorf("bad %s bool: %v ≠ %v\n", from, b.Bool, false)
|
||||
}
|
||||
if !b.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullBool(t *testing.T, b Bool, from string) {
|
||||
if b.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Byte is an nullable int.
|
||||
type Byte struct {
|
||||
Byte byte
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewByte creates a new Byte
|
||||
func NewByte(b byte, valid bool) Byte {
|
||||
return Byte{
|
||||
Byte: b,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// ByteFrom creates a new Byte that will always be valid.
|
||||
func ByteFrom(b byte) Byte {
|
||||
return NewByte(b, true)
|
||||
}
|
||||
|
||||
// ByteFromPtr creates a new Byte that be null if i is nil.
|
||||
func ByteFromPtr(b *byte) Byte {
|
||||
if b == nil {
|
||||
return NewByte(0, false)
|
||||
}
|
||||
return NewByte(*b, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (b *Byte) UnmarshalJSON(data []byte) error {
|
||||
if len(data) == 0 || bytes.Equal(data, NullBytes) {
|
||||
b.Valid = false
|
||||
b.Byte = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x string
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(x) > 1 {
|
||||
return errors.New("json: cannot convert to byte, text len is greater than one")
|
||||
}
|
||||
|
||||
b.Byte = x[0]
|
||||
b.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (b *Byte) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
b.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(text) > 1 {
|
||||
return errors.New("text: cannot convert to byte, text len is greater than one")
|
||||
}
|
||||
|
||||
b.Valid = true
|
||||
b.Byte = text[0]
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (b Byte) MarshalJSON() ([]byte, error) {
|
||||
if !b.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte{'"', b.Byte, '"'}, nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (b Byte) MarshalText() ([]byte, error) {
|
||||
if !b.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte{b.Byte}, nil
|
||||
}
|
||||
|
||||
// SetValid changes this Byte's value and also sets it to be non-null.
|
||||
func (b *Byte) SetValid(n byte) {
|
||||
b.Byte = n
|
||||
b.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Byte's value, or a nil pointer if this Byte is null.
|
||||
func (b Byte) Ptr() *byte {
|
||||
if !b.Valid {
|
||||
return nil
|
||||
}
|
||||
return &b.Byte
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Bytes, for future omitempty support (Go 1.4?)
|
||||
func (b Byte) IsNull() bool {
|
||||
return !b.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (b *Byte) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
b.Byte, b.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
|
||||
val := value.(string)
|
||||
if len(val) == 0 {
|
||||
b.Valid = false
|
||||
b.Byte = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
b.Valid = true
|
||||
b.Byte = byte(val[0])
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (b Byte) Value() (driver.Value, error) {
|
||||
if !b.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return []byte{b.Byte}, nil
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
byteJSON = []byte(`"b"`)
|
||||
)
|
||||
|
||||
func TestByteFrom(t *testing.T) {
|
||||
i := ByteFrom('b')
|
||||
assertByte(t, i, "ByteFrom()")
|
||||
|
||||
zero := ByteFrom(0)
|
||||
if !zero.Valid {
|
||||
t.Error("ByteFrom(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteFromPtr(t *testing.T) {
|
||||
n := byte('b')
|
||||
iptr := &n
|
||||
i := ByteFromPtr(iptr)
|
||||
assertByte(t, i, "ByteFromPtr()")
|
||||
|
||||
null := ByteFromPtr(nil)
|
||||
assertNullByte(t, null, "ByteFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalByte(t *testing.T) {
|
||||
var null Byte
|
||||
err := json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullByte(t, null, "null json")
|
||||
|
||||
var badType Byte
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullByte(t, badType, "wrong type json")
|
||||
|
||||
var invalid Byte
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullByte(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonByteegerNumber(t *testing.T) {
|
||||
var i Byte
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalByte(t *testing.T) {
|
||||
var i Byte
|
||||
err := i.UnmarshalText([]byte("b"))
|
||||
maybePanic(err)
|
||||
assertByte(t, i, "UnmarshalText() int")
|
||||
|
||||
var blank Byte
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullByte(t, blank, "UnmarshalText() empty int")
|
||||
}
|
||||
|
||||
func TestMarshalByte(t *testing.T) {
|
||||
i := ByteFrom('b')
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"b"`, "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewByte(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalByteText(t *testing.T) {
|
||||
i := ByteFrom('b')
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "b", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewByte(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestBytePointer(t *testing.T) {
|
||||
i := ByteFrom('b')
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 'b' {
|
||||
t.Errorf("bad %s int: %#v ≠ %d\n", "pointer", ptr, 'b')
|
||||
}
|
||||
|
||||
null := NewByte(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteIsNull(t *testing.T) {
|
||||
i := ByteFrom('b')
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewByte(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewByte(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestByteSetValid(t *testing.T) {
|
||||
change := NewByte(0, false)
|
||||
assertNullByte(t, change, "SetValid()")
|
||||
change.SetValid('b')
|
||||
assertByte(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestByteScan(t *testing.T) {
|
||||
var i Byte
|
||||
err := i.Scan("b")
|
||||
maybePanic(err)
|
||||
assertByte(t, i, "scanned int")
|
||||
|
||||
var null Byte
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullByte(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertByte(t *testing.T, i Byte, from string) {
|
||||
if i.Byte != 'b' {
|
||||
t.Errorf("bad %s int: %d ≠ %d\n", from, i.Byte, 'b')
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullByte(t *testing.T, i Byte, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// NullBytes is a global byte slice of JSON null
|
||||
var NullBytes = []byte("null")
|
||||
|
||||
// Bytes is a nullable []byte.
|
||||
type Bytes struct {
|
||||
Bytes []byte
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewBytes creates a new Bytes
|
||||
func NewBytes(b []byte, valid bool) Bytes {
|
||||
return Bytes{
|
||||
Bytes: b,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// BytesFrom creates a new Bytes that will be invalid if nil.
|
||||
func BytesFrom(b []byte) Bytes {
|
||||
return NewBytes(b, b != nil)
|
||||
}
|
||||
|
||||
// BytesFromPtr creates a new Bytes that will be invalid if nil.
|
||||
func BytesFromPtr(b *[]byte) Bytes {
|
||||
if b == nil {
|
||||
return NewBytes(nil, false)
|
||||
}
|
||||
n := NewBytes(*b, true)
|
||||
return n
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (b *Bytes) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
b.Valid = false
|
||||
b.Bytes = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
var s string
|
||||
if err := json.Unmarshal(data, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.Bytes = []byte(s)
|
||||
b.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (b *Bytes) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
b.Bytes = nil
|
||||
b.Valid = false
|
||||
} else {
|
||||
b.Bytes = append(b.Bytes[0:0], text...)
|
||||
b.Valid = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (b Bytes) MarshalJSON() ([]byte, error) {
|
||||
if len(b.Bytes) == 0 || b.Bytes == nil {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return b.Bytes, nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (b Bytes) MarshalText() ([]byte, error) {
|
||||
if !b.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return b.Bytes, nil
|
||||
}
|
||||
|
||||
// SetValid changes this Bytes's value and also sets it to be non-null.
|
||||
func (b *Bytes) SetValid(n []byte) {
|
||||
b.Bytes = n
|
||||
b.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Bytes's value, or a nil pointer if this Bytes is null.
|
||||
func (b Bytes) Ptr() *[]byte {
|
||||
if !b.Valid {
|
||||
return nil
|
||||
}
|
||||
return &b.Bytes
|
||||
}
|
||||
|
||||
// IsNull returns true for null or zero Bytes's, for future omitempty support (Go 1.4?)
|
||||
func (b Bytes) IsNull() bool {
|
||||
return !b.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (b *Bytes) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
b.Bytes, b.Valid = []byte{}, false
|
||||
return nil
|
||||
}
|
||||
b.Valid = true
|
||||
return convert.ConvertAssign(&b.Bytes, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (b Bytes) Value() (driver.Value, error) {
|
||||
if !b.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return b.Bytes, nil
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
bytesJSON = []byte(`"hello"`)
|
||||
)
|
||||
|
||||
func TestBytesFrom(t *testing.T) {
|
||||
i := BytesFrom([]byte(`hello`))
|
||||
assertBytes(t, i, "BytesFrom()")
|
||||
|
||||
zero := BytesFrom(nil)
|
||||
if zero.Valid {
|
||||
t.Error("BytesFrom(nil)", "is valid, but should be invalid")
|
||||
}
|
||||
|
||||
zero = BytesFrom([]byte{})
|
||||
if !zero.Valid {
|
||||
t.Error("BytesFrom([]byte{})", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesFromPtr(t *testing.T) {
|
||||
n := []byte(`hello`)
|
||||
iptr := &n
|
||||
i := BytesFromPtr(iptr)
|
||||
assertBytes(t, i, "BytesFromPtr()")
|
||||
|
||||
null := BytesFromPtr(nil)
|
||||
assertNullBytes(t, null, "BytesFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalBytes(t *testing.T) {
|
||||
var i Bytes
|
||||
err := json.Unmarshal(bytesJSON, &i)
|
||||
maybePanic(err)
|
||||
assertBytes(t, i, "[]byte json")
|
||||
|
||||
var ni Bytes
|
||||
err = ni.UnmarshalJSON([]byte{})
|
||||
if err == nil {
|
||||
t.Errorf("Expected error")
|
||||
}
|
||||
|
||||
var null Bytes
|
||||
err = null.UnmarshalJSON([]byte("null"))
|
||||
if null.Valid == true {
|
||||
t.Errorf("expected Valid to be false, got true")
|
||||
}
|
||||
if null.Bytes != nil {
|
||||
t.Errorf("Expected Bytes to be nil, but was not: %#v %#v", null.Bytes, []byte(`null`))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalBytes(t *testing.T) {
|
||||
var i Bytes
|
||||
err := i.UnmarshalText([]byte(`hello`))
|
||||
maybePanic(err)
|
||||
assertBytes(t, i, "UnmarshalText() []byte")
|
||||
|
||||
var blank Bytes
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullBytes(t, blank, "UnmarshalText() empty []byte")
|
||||
}
|
||||
|
||||
func TestMarshalBytes(t *testing.T) {
|
||||
i := BytesFrom([]byte(`"hello"`))
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"hello"`, "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewBytes(nil, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalBytesText(t *testing.T) {
|
||||
i := BytesFrom([]byte(`"hello"`))
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"hello"`, "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewBytes(nil, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestBytesPointer(t *testing.T) {
|
||||
i := BytesFrom([]byte(`"hello"`))
|
||||
ptr := i.Ptr()
|
||||
if !bytes.Equal(*ptr, []byte(`"hello"`)) {
|
||||
t.Errorf("bad %s []byte: %#v ≠ %s\n", "pointer", ptr, `"hello"`)
|
||||
}
|
||||
|
||||
null := NewBytes(nil, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s []byte: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesIsNull(t *testing.T) {
|
||||
i := BytesFrom([]byte(`"hello"`))
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewBytes(nil, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewBytes(nil, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBytesSetValid(t *testing.T) {
|
||||
change := NewBytes(nil, false)
|
||||
assertNullBytes(t, change, "SetValid()")
|
||||
change.SetValid([]byte(`hello`))
|
||||
assertBytes(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestBytesScan(t *testing.T) {
|
||||
var i Bytes
|
||||
err := i.Scan(`hello`)
|
||||
maybePanic(err)
|
||||
assertBytes(t, i, "Scan() []byte")
|
||||
|
||||
var null Bytes
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullBytes(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertBytes(t *testing.T, i Bytes, from string) {
|
||||
if !bytes.Equal(i.Bytes, []byte("hello")) {
|
||||
t.Errorf("bad %s []byte: %v ≠ %v\n", from, string(i.Bytes), string([]byte(`hello`)))
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullBytes(t *testing.T, i Bytes, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
package convert
|
||||
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Type conversions for Scan.
|
||||
// These functions are copied from database/sql/convert.go build 1.6.2
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errNilPtr = errors.New("destination pointer is nil") // embedded in descriptive error
|
||||
|
||||
// ConvertAssign copies to dest the value in src, converting it if possible.
|
||||
// An error is returned if the copy would result in loss of information.
|
||||
// dest should be a pointer type.
|
||||
func ConvertAssign(dest, src interface{}) error {
|
||||
// Common cases, without reflect.
|
||||
switch s := src.(type) {
|
||||
case string:
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = s
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = []byte(s)
|
||||
return nil
|
||||
}
|
||||
case []byte:
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = string(s)
|
||||
return nil
|
||||
case *interface{}:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = cloneBytes(s)
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = cloneBytes(s)
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = s
|
||||
return nil
|
||||
}
|
||||
case time.Time:
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
*d = s.Format(time.RFC3339Nano)
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = []byte(s.Format(time.RFC3339Nano))
|
||||
return nil
|
||||
}
|
||||
case nil:
|
||||
switch d := dest.(type) {
|
||||
case *interface{}:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var sv reflect.Value
|
||||
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
sv = reflect.ValueOf(src)
|
||||
switch sv.Kind() {
|
||||
case reflect.Bool,
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
*d = asString(src)
|
||||
return nil
|
||||
}
|
||||
case *[]byte:
|
||||
sv = reflect.ValueOf(src)
|
||||
if b, ok := asBytes(nil, sv); ok {
|
||||
*d = b
|
||||
return nil
|
||||
}
|
||||
case *sql.RawBytes:
|
||||
sv = reflect.ValueOf(src)
|
||||
if b, ok := asBytes([]byte(*d)[:0], sv); ok {
|
||||
*d = sql.RawBytes(b)
|
||||
return nil
|
||||
}
|
||||
case *bool:
|
||||
bv, err := driver.Bool.ConvertValue(src)
|
||||
if err == nil {
|
||||
*d = bv.(bool)
|
||||
}
|
||||
return err
|
||||
case *interface{}:
|
||||
*d = src
|
||||
return nil
|
||||
}
|
||||
|
||||
if scanner, ok := dest.(sql.Scanner); ok {
|
||||
return scanner.Scan(src)
|
||||
}
|
||||
|
||||
dpv := reflect.ValueOf(dest)
|
||||
if dpv.Kind() != reflect.Ptr {
|
||||
return errors.New("destination not a pointer")
|
||||
}
|
||||
if dpv.IsNil() {
|
||||
return errNilPtr
|
||||
}
|
||||
|
||||
if !sv.IsValid() {
|
||||
sv = reflect.ValueOf(src)
|
||||
}
|
||||
|
||||
dv := reflect.Indirect(dpv)
|
||||
if sv.IsValid() && sv.Type().AssignableTo(dv.Type()) {
|
||||
dv.Set(sv)
|
||||
return nil
|
||||
}
|
||||
|
||||
if dv.Kind() == sv.Kind() && sv.Type().ConvertibleTo(dv.Type()) {
|
||||
dv.Set(sv.Convert(dv.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
switch dv.Kind() {
|
||||
case reflect.Ptr:
|
||||
if src == nil {
|
||||
dv.Set(reflect.Zero(dv.Type()))
|
||||
return nil
|
||||
} else {
|
||||
dv.Set(reflect.New(dv.Type().Elem()))
|
||||
return ConvertAssign(dv.Interface(), src)
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
s := asString(src)
|
||||
i64, err := strconv.ParseInt(s, 10, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetInt(i64)
|
||||
return nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
s := asString(src)
|
||||
u64, err := strconv.ParseUint(s, 10, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetUint(u64)
|
||||
return nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
s := asString(src)
|
||||
f64, err := strconv.ParseFloat(s, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetFloat(f64)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("unsupported Scan, storing driver.Value type %T into type %T", src, dest)
|
||||
}
|
||||
|
||||
func strconvErr(err error) error {
|
||||
if ne, ok := err.(*strconv.NumError); ok {
|
||||
return ne.Err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func cloneBytes(b []byte) []byte {
|
||||
if b == nil {
|
||||
return nil
|
||||
} else {
|
||||
c := make([]byte, len(b))
|
||||
copy(c, b)
|
||||
return c
|
||||
}
|
||||
}
|
||||
|
||||
func asString(src interface{}) string {
|
||||
switch v := src.(type) {
|
||||
case string:
|
||||
return v
|
||||
case []byte:
|
||||
return string(v)
|
||||
}
|
||||
rv := reflect.ValueOf(src)
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.FormatInt(rv.Int(), 10)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return strconv.FormatUint(rv.Uint(), 10)
|
||||
case reflect.Float64:
|
||||
return strconv.FormatFloat(rv.Float(), 'g', -1, 64)
|
||||
case reflect.Float32:
|
||||
return strconv.FormatFloat(rv.Float(), 'g', -1, 32)
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(rv.Bool())
|
||||
}
|
||||
return fmt.Sprintf("%v", src)
|
||||
}
|
||||
|
||||
func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) {
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.AppendInt(buf, rv.Int(), 10), true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return strconv.AppendUint(buf, rv.Uint(), 10), true
|
||||
case reflect.Float32:
|
||||
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 32), true
|
||||
case reflect.Float64:
|
||||
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 64), true
|
||||
case reflect.Bool:
|
||||
return strconv.AppendBool(buf, rv.Bool()), true
|
||||
case reflect.String:
|
||||
s := rv.String()
|
||||
return append(buf, s...), true
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,382 +0,0 @@
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// These functions are copied from database/sql/convert_test.go build 1.6.2
|
||||
|
||||
package convert
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var someTime = time.Unix(123, 0)
|
||||
var answer int64 = 42
|
||||
|
||||
type userDefined float64
|
||||
|
||||
type userDefinedSlice []int
|
||||
|
||||
type conversionTest struct {
|
||||
s, d interface{} // source and destination
|
||||
|
||||
// following are used if they're non-zero
|
||||
wantint int64
|
||||
wantuint uint64
|
||||
wantstr string
|
||||
wantbytes []byte
|
||||
wantraw sql.RawBytes
|
||||
wantf32 float32
|
||||
wantf64 float64
|
||||
wanttime time.Time
|
||||
wantbool bool // used if d is of type *bool
|
||||
wanterr string
|
||||
wantiface interface{}
|
||||
wantptr *int64 // if non-nil, *d's pointed value must be equal to *wantptr
|
||||
wantnil bool // if true, *d must be *int64(nil)
|
||||
wantusrdef userDefined
|
||||
}
|
||||
|
||||
// Target variables for scanning into.
|
||||
var (
|
||||
scanstr string
|
||||
scanbytes []byte
|
||||
scanraw sql.RawBytes
|
||||
scanint int
|
||||
scanint8 int8
|
||||
scanint16 int16
|
||||
scanint32 int32
|
||||
scanuint8 uint8
|
||||
scanuint16 uint16
|
||||
scanbool bool
|
||||
scanf32 float32
|
||||
scanf64 float64
|
||||
scantime time.Time
|
||||
scanptr *int64
|
||||
scaniface interface{}
|
||||
)
|
||||
|
||||
var conversionTests = []conversionTest{
|
||||
// Exact conversions (destination pointer type matches source type)
|
||||
{s: "foo", d: &scanstr, wantstr: "foo"},
|
||||
{s: 123, d: &scanint, wantint: 123},
|
||||
{s: someTime, d: &scantime, wanttime: someTime},
|
||||
|
||||
// To strings
|
||||
{s: "string", d: &scanstr, wantstr: "string"},
|
||||
{s: []byte("byteslice"), d: &scanstr, wantstr: "byteslice"},
|
||||
{s: 123, d: &scanstr, wantstr: "123"},
|
||||
{s: int8(123), d: &scanstr, wantstr: "123"},
|
||||
{s: int64(123), d: &scanstr, wantstr: "123"},
|
||||
{s: uint8(123), d: &scanstr, wantstr: "123"},
|
||||
{s: uint16(123), d: &scanstr, wantstr: "123"},
|
||||
{s: uint32(123), d: &scanstr, wantstr: "123"},
|
||||
{s: uint64(123), d: &scanstr, wantstr: "123"},
|
||||
{s: 1.5, d: &scanstr, wantstr: "1.5"},
|
||||
|
||||
// From time.Time:
|
||||
{s: time.Unix(1, 0).UTC(), d: &scanstr, wantstr: "1970-01-01T00:00:01Z"},
|
||||
{s: time.Unix(1453874597, 0).In(time.FixedZone("here", -3600*8)), d: &scanstr, wantstr: "2016-01-26T22:03:17-08:00"},
|
||||
{s: time.Unix(1, 2).UTC(), d: &scanstr, wantstr: "1970-01-01T00:00:01.000000002Z"},
|
||||
{s: time.Time{}, d: &scanstr, wantstr: "0001-01-01T00:00:00Z"},
|
||||
{s: time.Unix(1, 2).UTC(), d: &scanbytes, wantbytes: []byte("1970-01-01T00:00:01.000000002Z")},
|
||||
{s: time.Unix(1, 2).UTC(), d: &scaniface, wantiface: time.Unix(1, 2).UTC()},
|
||||
|
||||
// To []byte
|
||||
{s: nil, d: &scanbytes, wantbytes: nil},
|
||||
{s: "string", d: &scanbytes, wantbytes: []byte("string")},
|
||||
{s: []byte("byteslice"), d: &scanbytes, wantbytes: []byte("byteslice")},
|
||||
{s: 123, d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: int8(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: int64(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: uint8(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: uint16(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: uint32(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: uint64(123), d: &scanbytes, wantbytes: []byte("123")},
|
||||
{s: 1.5, d: &scanbytes, wantbytes: []byte("1.5")},
|
||||
|
||||
// To sql.RawBytes
|
||||
{s: nil, d: &scanraw, wantraw: nil},
|
||||
{s: []byte("byteslice"), d: &scanraw, wantraw: sql.RawBytes("byteslice")},
|
||||
{s: 123, d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: int8(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: int64(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: uint8(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: uint16(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: uint32(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: uint64(123), d: &scanraw, wantraw: sql.RawBytes("123")},
|
||||
{s: 1.5, d: &scanraw, wantraw: sql.RawBytes("1.5")},
|
||||
|
||||
// Strings to integers
|
||||
{s: "255", d: &scanuint8, wantuint: 255},
|
||||
{s: "256", d: &scanuint8, wanterr: "converting driver.Value type string (\"256\") to a uint8: value out of range"},
|
||||
{s: "256", d: &scanuint16, wantuint: 256},
|
||||
{s: "-1", d: &scanint, wantint: -1},
|
||||
{s: "foo", d: &scanint, wanterr: "converting driver.Value type string (\"foo\") to a int: invalid syntax"},
|
||||
|
||||
// int64 to smaller integers
|
||||
{s: int64(5), d: &scanuint8, wantuint: 5},
|
||||
{s: int64(256), d: &scanuint8, wanterr: "converting driver.Value type int64 (\"256\") to a uint8: value out of range"},
|
||||
{s: int64(256), d: &scanuint16, wantuint: 256},
|
||||
{s: int64(65536), d: &scanuint16, wanterr: "converting driver.Value type int64 (\"65536\") to a uint16: value out of range"},
|
||||
|
||||
// True bools
|
||||
{s: true, d: &scanbool, wantbool: true},
|
||||
{s: "True", d: &scanbool, wantbool: true},
|
||||
{s: "TRUE", d: &scanbool, wantbool: true},
|
||||
{s: "1", d: &scanbool, wantbool: true},
|
||||
{s: 1, d: &scanbool, wantbool: true},
|
||||
{s: int64(1), d: &scanbool, wantbool: true},
|
||||
{s: uint16(1), d: &scanbool, wantbool: true},
|
||||
|
||||
// False bools
|
||||
{s: false, d: &scanbool, wantbool: false},
|
||||
{s: "false", d: &scanbool, wantbool: false},
|
||||
{s: "FALSE", d: &scanbool, wantbool: false},
|
||||
{s: "0", d: &scanbool, wantbool: false},
|
||||
{s: 0, d: &scanbool, wantbool: false},
|
||||
{s: int64(0), d: &scanbool, wantbool: false},
|
||||
{s: uint16(0), d: &scanbool, wantbool: false},
|
||||
|
||||
// Not bools
|
||||
{s: "yup", d: &scanbool, wanterr: `sql/driver: couldn't convert "yup" into type bool`},
|
||||
{s: 2, d: &scanbool, wanterr: `sql/driver: couldn't convert 2 into type bool`},
|
||||
|
||||
// Floats
|
||||
{s: float64(1.5), d: &scanf64, wantf64: float64(1.5)},
|
||||
{s: int64(1), d: &scanf64, wantf64: float64(1)},
|
||||
{s: float64(1.5), d: &scanf32, wantf32: float32(1.5)},
|
||||
{s: "1.5", d: &scanf32, wantf32: float32(1.5)},
|
||||
{s: "1.5", d: &scanf64, wantf64: float64(1.5)},
|
||||
|
||||
// Pointers
|
||||
{s: interface{}(nil), d: &scanptr, wantnil: true},
|
||||
{s: int64(42), d: &scanptr, wantptr: &answer},
|
||||
|
||||
// To interface{}
|
||||
{s: float64(1.5), d: &scaniface, wantiface: float64(1.5)},
|
||||
{s: int64(1), d: &scaniface, wantiface: int64(1)},
|
||||
{s: "str", d: &scaniface, wantiface: "str"},
|
||||
{s: []byte("byteslice"), d: &scaniface, wantiface: []byte("byteslice")},
|
||||
{s: true, d: &scaniface, wantiface: true},
|
||||
{s: nil, d: &scaniface},
|
||||
{s: []byte(nil), d: &scaniface, wantiface: []byte(nil)},
|
||||
|
||||
// To a user-defined type
|
||||
{s: 1.5, d: new(userDefined), wantusrdef: 1.5},
|
||||
{s: int64(123), d: new(userDefined), wantusrdef: 123},
|
||||
{s: "1.5", d: new(userDefined), wantusrdef: 1.5},
|
||||
{s: []byte{1, 2, 3}, d: new(userDefinedSlice), wanterr: `unsupported Scan, storing driver.Value type []uint8 into type *convert.userDefinedSlice`},
|
||||
|
||||
// Other errors
|
||||
{s: complex(1, 2), d: &scanstr, wanterr: `unsupported Scan, storing driver.Value type complex128 into type *string`},
|
||||
}
|
||||
|
||||
func intPtrValue(intptr interface{}) interface{} {
|
||||
return reflect.Indirect(reflect.Indirect(reflect.ValueOf(intptr))).Int()
|
||||
}
|
||||
|
||||
func intValue(intptr interface{}) int64 {
|
||||
return reflect.Indirect(reflect.ValueOf(intptr)).Int()
|
||||
}
|
||||
|
||||
func uintValue(intptr interface{}) uint64 {
|
||||
return reflect.Indirect(reflect.ValueOf(intptr)).Uint()
|
||||
}
|
||||
|
||||
func float64Value(ptr interface{}) float64 {
|
||||
return *(ptr.(*float64))
|
||||
}
|
||||
|
||||
func float32Value(ptr interface{}) float32 {
|
||||
return *(ptr.(*float32))
|
||||
}
|
||||
|
||||
func getTimeValue(ptr interface{}) time.Time {
|
||||
return *(ptr.(*time.Time))
|
||||
}
|
||||
|
||||
func TestConversions(t *testing.T) {
|
||||
for n, ct := range conversionTests {
|
||||
err := ConvertAssign(ct.d, ct.s)
|
||||
errstr := ""
|
||||
if err != nil {
|
||||
errstr = err.Error()
|
||||
}
|
||||
errf := func(format string, args ...interface{}) {
|
||||
base := fmt.Sprintf("ConvertAssign #%d: for %v (%T) -> %T, ", n, ct.s, ct.s, ct.d)
|
||||
t.Errorf(base+format, args...)
|
||||
}
|
||||
if errstr != ct.wanterr {
|
||||
errf("got error %q, want error %q", errstr, ct.wanterr)
|
||||
}
|
||||
if ct.wantstr != "" && ct.wantstr != scanstr {
|
||||
errf("want string %q, got %q", ct.wantstr, scanstr)
|
||||
}
|
||||
if ct.wantint != 0 && ct.wantint != intValue(ct.d) {
|
||||
errf("want int %d, got %d", ct.wantint, intValue(ct.d))
|
||||
}
|
||||
if ct.wantuint != 0 && ct.wantuint != uintValue(ct.d) {
|
||||
errf("want uint %d, got %d", ct.wantuint, uintValue(ct.d))
|
||||
}
|
||||
if ct.wantf32 != 0 && ct.wantf32 != float32Value(ct.d) {
|
||||
errf("want float32 %v, got %v", ct.wantf32, float32Value(ct.d))
|
||||
}
|
||||
if ct.wantf64 != 0 && ct.wantf64 != float64Value(ct.d) {
|
||||
errf("want float32 %v, got %v", ct.wantf64, float64Value(ct.d))
|
||||
}
|
||||
if bp, boolTest := ct.d.(*bool); boolTest && *bp != ct.wantbool && ct.wanterr == "" {
|
||||
errf("want bool %v, got %v", ct.wantbool, *bp)
|
||||
}
|
||||
if !ct.wanttime.IsZero() && !ct.wanttime.Equal(getTimeValue(ct.d)) {
|
||||
errf("want time %v, got %v", ct.wanttime, getTimeValue(ct.d))
|
||||
}
|
||||
if ct.wantnil && *ct.d.(**int64) != nil {
|
||||
errf("want nil, got %v", intPtrValue(ct.d))
|
||||
}
|
||||
if ct.wantptr != nil {
|
||||
if *ct.d.(**int64) == nil {
|
||||
errf("want pointer to %v, got nil", *ct.wantptr)
|
||||
} else if *ct.wantptr != intPtrValue(ct.d) {
|
||||
errf("want pointer to %v, got %v", *ct.wantptr, intPtrValue(ct.d))
|
||||
}
|
||||
}
|
||||
if ifptr, ok := ct.d.(*interface{}); ok {
|
||||
if !reflect.DeepEqual(ct.wantiface, scaniface) {
|
||||
errf("want interface %#v, got %#v", ct.wantiface, scaniface)
|
||||
continue
|
||||
}
|
||||
if srcBytes, ok := ct.s.([]byte); ok {
|
||||
dstBytes := (*ifptr).([]byte)
|
||||
if len(srcBytes) > 0 && &dstBytes[0] == &srcBytes[0] {
|
||||
errf("copy into interface{} didn't copy []byte data")
|
||||
}
|
||||
}
|
||||
}
|
||||
if ct.wantusrdef != 0 && ct.wantusrdef != *ct.d.(*userDefined) {
|
||||
errf("want userDefined %f, got %f", ct.wantusrdef, *ct.d.(*userDefined))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestNullString(t *testing.T) {
|
||||
var ns sql.NullString
|
||||
ConvertAssign(&ns, []byte("foo"))
|
||||
if !ns.Valid {
|
||||
t.Errorf("expecting not null")
|
||||
}
|
||||
if ns.String != "foo" {
|
||||
t.Errorf("expecting foo; got %q", ns.String)
|
||||
}
|
||||
ConvertAssign(&ns, nil)
|
||||
if ns.Valid {
|
||||
t.Errorf("expecting null on nil")
|
||||
}
|
||||
if ns.String != "" {
|
||||
t.Errorf("expecting blank on nil; got %q", ns.String)
|
||||
}
|
||||
}
|
||||
|
||||
type valueConverterTest struct {
|
||||
c driver.ValueConverter
|
||||
in, out interface{}
|
||||
err string
|
||||
}
|
||||
|
||||
var valueConverterTests = []valueConverterTest{
|
||||
{driver.DefaultParameterConverter, sql.NullString{"hi", true}, "hi", ""},
|
||||
{driver.DefaultParameterConverter, sql.NullString{"", false}, nil, ""},
|
||||
}
|
||||
|
||||
func TestValueConverters(t *testing.T) {
|
||||
for i, tt := range valueConverterTests {
|
||||
out, err := tt.c.ConvertValue(tt.in)
|
||||
goterr := ""
|
||||
if err != nil {
|
||||
goterr = err.Error()
|
||||
}
|
||||
if goterr != tt.err {
|
||||
t.Errorf("test %d: %T(%T(%v)) error = %q; want error = %q",
|
||||
i, tt.c, tt.in, tt.in, goterr, tt.err)
|
||||
}
|
||||
if tt.err != "" {
|
||||
continue
|
||||
}
|
||||
if !reflect.DeepEqual(out, tt.out) {
|
||||
t.Errorf("test %d: %T(%T(%v)) = %v (%T); want %v (%T)",
|
||||
i, tt.c, tt.in, tt.in, out, out, tt.out, tt.out)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tests that assigning to sql.RawBytes doesn't allocate (and also works).
|
||||
func TestRawBytesAllocs(t *testing.T) {
|
||||
var tests = []struct {
|
||||
name string
|
||||
in interface{}
|
||||
want string
|
||||
}{
|
||||
{"uint64", uint64(12345678), "12345678"},
|
||||
{"uint32", uint32(1234), "1234"},
|
||||
{"uint16", uint16(12), "12"},
|
||||
{"uint8", uint8(1), "1"},
|
||||
{"uint", uint(123), "123"},
|
||||
{"int", int(123), "123"},
|
||||
{"int8", int8(1), "1"},
|
||||
{"int16", int16(12), "12"},
|
||||
{"int32", int32(1234), "1234"},
|
||||
{"int64", int64(12345678), "12345678"},
|
||||
{"float32", float32(1.5), "1.5"},
|
||||
{"float64", float64(64), "64"},
|
||||
{"bool", false, "false"},
|
||||
}
|
||||
|
||||
buf := make(sql.RawBytes, 10)
|
||||
test := func(name string, in interface{}, want string) {
|
||||
if err := ConvertAssign(&buf, in); err != nil {
|
||||
t.Fatalf("%s: ConvertAssign = %v", name, err)
|
||||
}
|
||||
match := len(buf) == len(want)
|
||||
if match {
|
||||
for i, b := range buf {
|
||||
if want[i] != b {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !match {
|
||||
t.Fatalf("%s: got %q (len %d); want %q (len %d)", name, buf, len(buf), want, len(want))
|
||||
}
|
||||
}
|
||||
|
||||
n := testing.AllocsPerRun(100, func() {
|
||||
for _, tt := range tests {
|
||||
test(tt.name, tt.in, tt.want)
|
||||
}
|
||||
})
|
||||
|
||||
// The numbers below are only valid for 64-bit interface word sizes,
|
||||
// and gc. With 32-bit words there are more convT2E allocs, and
|
||||
// with gccgo, only pointers currently go in interface data.
|
||||
// So only care on amd64 gc for now.
|
||||
measureAllocs := runtime.GOARCH == "amd64" && runtime.Compiler == "gc"
|
||||
|
||||
if n > 0.5 && measureAllocs {
|
||||
t.Fatalf("allocs = %v; want 0", n)
|
||||
}
|
||||
|
||||
// This one involves a convT2E allocation, string -> interface{}
|
||||
n = testing.AllocsPerRun(100, func() {
|
||||
test("string", "foo", "foo")
|
||||
})
|
||||
if n > 1.5 && measureAllocs {
|
||||
t.Fatalf("allocs = %v; want max 1", n)
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Float32 is a nullable float32.
|
||||
type Float32 struct {
|
||||
Float32 float32
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewFloat32 creates a new Float32
|
||||
func NewFloat32(f float32, valid bool) Float32 {
|
||||
return Float32{
|
||||
Float32: f,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Float32From creates a new Float32 that will always be valid.
|
||||
func Float32From(f float32) Float32 {
|
||||
return NewFloat32(f, true)
|
||||
}
|
||||
|
||||
// Float32FromPtr creates a new Float32 that be null if f is nil.
|
||||
func Float32FromPtr(f *float32) Float32 {
|
||||
if f == nil {
|
||||
return NewFloat32(0, false)
|
||||
}
|
||||
return NewFloat32(*f, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (f *Float32) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
f.Valid = false
|
||||
f.Float32 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x float64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.Float32 = float32(x)
|
||||
f.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (f *Float32) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
f.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseFloat(string(text), 32)
|
||||
f.Valid = err == nil
|
||||
if f.Valid {
|
||||
f.Float32 = float32(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (f Float32) MarshalJSON() ([]byte, error) {
|
||||
if !f.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatFloat(float64(f.Float32), 'f', -1, 32)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (f Float32) MarshalText() ([]byte, error) {
|
||||
if !f.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatFloat(float64(f.Float32), 'f', -1, 32)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Float32's value and also sets it to be non-null.
|
||||
func (f *Float32) SetValid(n float32) {
|
||||
f.Float32 = n
|
||||
f.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Float32's value, or a nil pointer if this Float32 is null.
|
||||
func (f Float32) Ptr() *float32 {
|
||||
if !f.Valid {
|
||||
return nil
|
||||
}
|
||||
return &f.Float32
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Float32s, for future omitempty support (Go 1.4?)
|
||||
func (f Float32) IsNull() bool {
|
||||
return !f.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (f *Float32) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
f.Float32, f.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
f.Valid = true
|
||||
return convert.ConvertAssign(&f.Float32, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (f Float32) Value() (driver.Value, error) {
|
||||
if !f.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return float64(f.Float32), nil
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
float32JSON = []byte(`1.2345`)
|
||||
)
|
||||
|
||||
func TestFloat32From(t *testing.T) {
|
||||
f := Float32From(1.2345)
|
||||
assertFloat32(t, f, "Float32From()")
|
||||
|
||||
zero := Float32From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Float32From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32FromPtr(t *testing.T) {
|
||||
n := float32(1.2345)
|
||||
iptr := &n
|
||||
f := Float32FromPtr(iptr)
|
||||
assertFloat32(t, f, "Float32FromPtr()")
|
||||
|
||||
null := Float32FromPtr(nil)
|
||||
assertNullFloat32(t, null, "Float32FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalFloat32(t *testing.T) {
|
||||
var f Float32
|
||||
err := json.Unmarshal(float32JSON, &f)
|
||||
maybePanic(err)
|
||||
assertFloat32(t, f, "float32 json")
|
||||
|
||||
var null Float32
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullFloat32(t, null, "null json")
|
||||
|
||||
var badType Float32
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullFloat32(t, badType, "wrong type json")
|
||||
|
||||
var invalid Float32
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalFloat32(t *testing.T) {
|
||||
var f Float32
|
||||
err := f.UnmarshalText([]byte("1.2345"))
|
||||
maybePanic(err)
|
||||
assertFloat32(t, f, "UnmarshalText() float32")
|
||||
|
||||
var blank Float32
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullFloat32(t, blank, "UnmarshalText() empty float32")
|
||||
}
|
||||
|
||||
func TestMarshalFloat32(t *testing.T) {
|
||||
f := Float32From(1.2345)
|
||||
data, err := json.Marshal(f)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "1.2345", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewFloat32(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalFloat32Text(t *testing.T) {
|
||||
f := Float32From(1.2345)
|
||||
data, err := f.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "1.2345", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewFloat32(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestFloat32Pointer(t *testing.T) {
|
||||
f := Float32From(1.2345)
|
||||
ptr := f.Ptr()
|
||||
if *ptr != 1.2345 {
|
||||
t.Errorf("bad %s float32: %#v ≠ %v\n", "pointer", ptr, 1.2345)
|
||||
}
|
||||
|
||||
null := NewFloat32(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s float32: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32IsNull(t *testing.T) {
|
||||
f := Float32From(1.2345)
|
||||
if f.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewFloat32(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewFloat32(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat32SetValid(t *testing.T) {
|
||||
change := NewFloat32(0, false)
|
||||
assertNullFloat32(t, change, "SetValid()")
|
||||
change.SetValid(1.2345)
|
||||
assertFloat32(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestFloat32Scan(t *testing.T) {
|
||||
var f Float32
|
||||
err := f.Scan(1.2345)
|
||||
maybePanic(err)
|
||||
assertFloat32(t, f, "scanned float32")
|
||||
|
||||
var null Float32
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullFloat32(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertFloat32(t *testing.T, f Float32, from string) {
|
||||
if f.Float32 != 1.2345 {
|
||||
t.Errorf("bad %s float32: %f ≠ %f\n", from, f.Float32, 1.2345)
|
||||
}
|
||||
if !f.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullFloat32(t *testing.T, f Float32, from string) {
|
||||
if f.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Float64 is a nullable float64.
|
||||
type Float64 struct {
|
||||
Float64 float64
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewFloat64 creates a new Float64
|
||||
func NewFloat64(f float64, valid bool) Float64 {
|
||||
return Float64{
|
||||
Float64: f,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Float64From creates a new Float64 that will always be valid.
|
||||
func Float64From(f float64) Float64 {
|
||||
return NewFloat64(f, true)
|
||||
}
|
||||
|
||||
// Float64FromPtr creates a new Float64 that be null if f is nil.
|
||||
func Float64FromPtr(f *float64) Float64 {
|
||||
if f == nil {
|
||||
return NewFloat64(0, false)
|
||||
}
|
||||
return NewFloat64(*f, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (f *Float64) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
f.Float64 = 0
|
||||
f.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &f.Float64); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (f *Float64) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
f.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
f.Float64, err = strconv.ParseFloat(string(text), 64)
|
||||
f.Valid = err == nil
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (f Float64) MarshalJSON() ([]byte, error) {
|
||||
if !f.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatFloat(f.Float64, 'f', -1, 64)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (f Float64) MarshalText() ([]byte, error) {
|
||||
if !f.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatFloat(f.Float64, 'f', -1, 64)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Float64's value and also sets it to be non-null.
|
||||
func (f *Float64) SetValid(n float64) {
|
||||
f.Float64 = n
|
||||
f.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Float64's value, or a nil pointer if this Float64 is null.
|
||||
func (f Float64) Ptr() *float64 {
|
||||
if !f.Valid {
|
||||
return nil
|
||||
}
|
||||
return &f.Float64
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Float64s, for future omitempty support (Go 1.4?)
|
||||
func (f Float64) IsNull() bool {
|
||||
return !f.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (f *Float64) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
f.Float64, f.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
f.Valid = true
|
||||
return convert.ConvertAssign(&f.Float64, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (f Float64) Value() (driver.Value, error) {
|
||||
if !f.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return f.Float64, nil
|
||||
}
|
||||
@@ -1,164 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
float64JSON = []byte(`1.2345`)
|
||||
)
|
||||
|
||||
func TestFloat64From(t *testing.T) {
|
||||
f := Float64From(1.2345)
|
||||
assertFloat64(t, f, "Float64From()")
|
||||
|
||||
zero := Float64From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Float64From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64FromPtr(t *testing.T) {
|
||||
n := float64(1.2345)
|
||||
iptr := &n
|
||||
f := Float64FromPtr(iptr)
|
||||
assertFloat64(t, f, "Float64FromPtr()")
|
||||
|
||||
null := Float64FromPtr(nil)
|
||||
assertNullFloat64(t, null, "Float64FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalFloat64(t *testing.T) {
|
||||
var f Float64
|
||||
err := json.Unmarshal(float64JSON, &f)
|
||||
maybePanic(err)
|
||||
assertFloat64(t, f, "float64 json")
|
||||
|
||||
var null Float64
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullFloat64(t, null, "null json")
|
||||
|
||||
var badType Float64
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullFloat64(t, badType, "wrong type json")
|
||||
|
||||
var invalid Float64
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalFloat64(t *testing.T) {
|
||||
var f Float64
|
||||
err := f.UnmarshalText([]byte("1.2345"))
|
||||
maybePanic(err)
|
||||
assertFloat64(t, f, "UnmarshalText() float64")
|
||||
|
||||
var blank Float64
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullFloat64(t, blank, "UnmarshalText() empty float64")
|
||||
}
|
||||
|
||||
func TestMarshalFloat64(t *testing.T) {
|
||||
f := Float64From(1.2345)
|
||||
data, err := json.Marshal(f)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "1.2345", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewFloat64(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalFloat64Text(t *testing.T) {
|
||||
f := Float64From(1.2345)
|
||||
data, err := f.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "1.2345", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewFloat64(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestFloat64Pointer(t *testing.T) {
|
||||
f := Float64From(1.2345)
|
||||
ptr := f.Ptr()
|
||||
if *ptr != 1.2345 {
|
||||
t.Errorf("bad %s float64: %#v ≠ %v\n", "pointer", ptr, 1.2345)
|
||||
}
|
||||
|
||||
null := NewFloat64(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s float64: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64IsNull(t *testing.T) {
|
||||
f := Float64From(1.2345)
|
||||
if f.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewFloat64(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewFloat64(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFloat64SetValid(t *testing.T) {
|
||||
change := NewFloat64(0, false)
|
||||
assertNullFloat64(t, change, "SetValid()")
|
||||
change.SetValid(1.2345)
|
||||
assertFloat64(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestFloat64Scan(t *testing.T) {
|
||||
var f Float64
|
||||
err := f.Scan(1.2345)
|
||||
maybePanic(err)
|
||||
assertFloat64(t, f, "scanned float64")
|
||||
|
||||
var null Float64
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullFloat64(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertFloat64(t *testing.T, f Float64, from string) {
|
||||
if f.Float64 != 1.2345 {
|
||||
t.Errorf("bad %s float64: %f ≠ %f\n", from, f.Float64, 1.2345)
|
||||
}
|
||||
if !f.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullFloat64(t *testing.T, f Float64, from string) {
|
||||
if f.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Int is an nullable int.
|
||||
type Int struct {
|
||||
Int int
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewInt creates a new Int
|
||||
func NewInt(i int, valid bool) Int {
|
||||
return Int{
|
||||
Int: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// IntFrom creates a new Int that will always be valid.
|
||||
func IntFrom(i int) Int {
|
||||
return NewInt(i, true)
|
||||
}
|
||||
|
||||
// IntFromPtr creates a new Int that be null if i is nil.
|
||||
func IntFromPtr(i *int) Int {
|
||||
if i == nil {
|
||||
return NewInt(0, false)
|
||||
}
|
||||
return NewInt(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (i *Int) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
i.Valid = false
|
||||
i.Int = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x int64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Int = int(x)
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (i *Int) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseInt(string(text), 10, 0)
|
||||
i.Valid = err == nil
|
||||
if i.Valid {
|
||||
i.Int = int(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (i Int) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (i Int) MarshalText() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Int's value and also sets it to be non-null.
|
||||
func (i *Int) SetValid(n int) {
|
||||
i.Int = n
|
||||
i.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Int's value, or a nil pointer if this Int is null.
|
||||
func (i Int) Ptr() *int {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
return &i.Int
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Ints, for future omitempty support (Go 1.4?)
|
||||
func (i Int) IsNull() bool {
|
||||
return !i.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (i *Int) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
i.Int, i.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
i.Valid = true
|
||||
return convert.ConvertAssign(&i.Int, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (i Int) Value() (driver.Value, error) {
|
||||
if !i.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(i.Int), nil
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Int16 is an nullable int16.
|
||||
type Int16 struct {
|
||||
Int16 int16
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewInt16 creates a new Int16
|
||||
func NewInt16(i int16, valid bool) Int16 {
|
||||
return Int16{
|
||||
Int16: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Int16From creates a new Int16 that will always be valid.
|
||||
func Int16From(i int16) Int16 {
|
||||
return NewInt16(i, true)
|
||||
}
|
||||
|
||||
// Int16FromPtr creates a new Int16 that be null if i is nil.
|
||||
func Int16FromPtr(i *int16) Int16 {
|
||||
if i == nil {
|
||||
return NewInt16(0, false)
|
||||
}
|
||||
return NewInt16(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (i *Int16) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
i.Valid = false
|
||||
i.Int16 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x int64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxInt16 {
|
||||
return fmt.Errorf("json: %d overflows max int16 value", x)
|
||||
}
|
||||
|
||||
i.Int16 = int16(x)
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (i *Int16) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseInt(string(text), 10, 16)
|
||||
i.Valid = err == nil
|
||||
if i.Valid {
|
||||
i.Int16 = int16(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (i Int16) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int16), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (i Int16) MarshalText() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int16), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Int16's value and also sets it to be non-null.
|
||||
func (i *Int16) SetValid(n int16) {
|
||||
i.Int16 = n
|
||||
i.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Int16's value, or a nil pointer if this Int16 is null.
|
||||
func (i Int16) Ptr() *int16 {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
return &i.Int16
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Int16's, for future omitempty support (Go 1.4?)
|
||||
func (i Int16) IsNull() bool {
|
||||
return !i.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (i *Int16) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
i.Int16, i.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
i.Valid = true
|
||||
return convert.ConvertAssign(&i.Int16, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (i Int16) Value() (driver.Value, error) {
|
||||
if !i.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(i.Int16), nil
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
int16JSON = []byte(`32766`)
|
||||
)
|
||||
|
||||
func TestInt16From(t *testing.T) {
|
||||
i := Int16From(32766)
|
||||
assertInt16(t, i, "Int16From()")
|
||||
|
||||
zero := Int16From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Int16From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt16FromPtr(t *testing.T) {
|
||||
n := int16(32766)
|
||||
iptr := &n
|
||||
i := Int16FromPtr(iptr)
|
||||
assertInt16(t, i, "Int16FromPtr()")
|
||||
|
||||
null := Int16FromPtr(nil)
|
||||
assertNullInt16(t, null, "Int16FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalInt16(t *testing.T) {
|
||||
var i Int16
|
||||
err := json.Unmarshal(int16JSON, &i)
|
||||
maybePanic(err)
|
||||
assertInt16(t, i, "int16 json")
|
||||
|
||||
var null Int16
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullInt16(t, null, "null json")
|
||||
|
||||
var badType Int16
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullInt16(t, badType, "wrong type json")
|
||||
|
||||
var invalid Int16
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullInt16(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonIntegerNumber16(t *testing.T) {
|
||||
var i Int16
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int16")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalInt16Overflow(t *testing.T) {
|
||||
int16Overflow := uint16(math.MaxInt16)
|
||||
|
||||
// Max int16 should decode successfully
|
||||
var i Int16
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(int16Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
// Attempt to overflow
|
||||
int16Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(int16Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows int16")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalInt16(t *testing.T) {
|
||||
var i Int16
|
||||
err := i.UnmarshalText([]byte("32766"))
|
||||
maybePanic(err)
|
||||
assertInt16(t, i, "UnmarshalText() int16")
|
||||
|
||||
var blank Int16
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullInt16(t, blank, "UnmarshalText() empty int16")
|
||||
}
|
||||
|
||||
func TestMarshalInt16(t *testing.T) {
|
||||
i := Int16From(32766)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "32766", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt16(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalInt16Text(t *testing.T) {
|
||||
i := Int16From(32766)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "32766", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt16(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestInt16Pointer(t *testing.T) {
|
||||
i := Int16From(32766)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 32766 {
|
||||
t.Errorf("bad %s int16: %#v ≠ %d\n", "pointer", ptr, 32766)
|
||||
}
|
||||
|
||||
null := NewInt16(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int16: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt16IsNull(t *testing.T) {
|
||||
i := Int16From(32766)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewInt16(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewInt16(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt16SetValid(t *testing.T) {
|
||||
change := NewInt16(0, false)
|
||||
assertNullInt16(t, change, "SetValid()")
|
||||
change.SetValid(32766)
|
||||
assertInt16(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestInt16Scan(t *testing.T) {
|
||||
var i Int16
|
||||
err := i.Scan(32766)
|
||||
maybePanic(err)
|
||||
assertInt16(t, i, "scanned int16")
|
||||
|
||||
var null Int16
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullInt16(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertInt16(t *testing.T, i Int16, from string) {
|
||||
if i.Int16 != 32766 {
|
||||
t.Errorf("bad %s int16: %d ≠ %d\n", from, i.Int16, 32766)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullInt16(t *testing.T, i Int16, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Int32 is an nullable int32.
|
||||
type Int32 struct {
|
||||
Int32 int32
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewInt32 creates a new Int32
|
||||
func NewInt32(i int32, valid bool) Int32 {
|
||||
return Int32{
|
||||
Int32: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Int32From creates a new Int32 that will always be valid.
|
||||
func Int32From(i int32) Int32 {
|
||||
return NewInt32(i, true)
|
||||
}
|
||||
|
||||
// Int32FromPtr creates a new Int32 that be null if i is nil.
|
||||
func Int32FromPtr(i *int32) Int32 {
|
||||
if i == nil {
|
||||
return NewInt32(0, false)
|
||||
}
|
||||
return NewInt32(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (i *Int32) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
i.Valid = false
|
||||
i.Int32 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x int64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxInt32 {
|
||||
return fmt.Errorf("json: %d overflows max int32 value", x)
|
||||
}
|
||||
|
||||
i.Int32 = int32(x)
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (i *Int32) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseInt(string(text), 10, 32)
|
||||
i.Valid = err == nil
|
||||
if i.Valid {
|
||||
i.Int32 = int32(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (i Int32) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int32), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (i Int32) MarshalText() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int32), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Int32's value and also sets it to be non-null.
|
||||
func (i *Int32) SetValid(n int32) {
|
||||
i.Int32 = n
|
||||
i.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Int32's value, or a nil pointer if this Int32 is null.
|
||||
func (i Int32) Ptr() *int32 {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
return &i.Int32
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Int32's, for future omitempty support (Go 1.4?)
|
||||
func (i Int32) IsNull() bool {
|
||||
return !i.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (i *Int32) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
i.Int32, i.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
i.Valid = true
|
||||
return convert.ConvertAssign(&i.Int32, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (i Int32) Value() (driver.Value, error) {
|
||||
if !i.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(i.Int32), nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
int32JSON = []byte(`2147483646`)
|
||||
)
|
||||
|
||||
func TestInt32From(t *testing.T) {
|
||||
i := Int32From(2147483646)
|
||||
assertInt32(t, i, "Int32From()")
|
||||
|
||||
zero := Int32From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Int32From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32FromPtr(t *testing.T) {
|
||||
n := int32(2147483646)
|
||||
iptr := &n
|
||||
i := Int32FromPtr(iptr)
|
||||
assertInt32(t, i, "Int32FromPtr()")
|
||||
|
||||
null := Int32FromPtr(nil)
|
||||
assertNullInt32(t, null, "Int32FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalInt32(t *testing.T) {
|
||||
var i Int32
|
||||
err := json.Unmarshal(int32JSON, &i)
|
||||
maybePanic(err)
|
||||
assertInt32(t, i, "int32 json")
|
||||
|
||||
var null Int32
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullInt32(t, null, "null json")
|
||||
|
||||
var badType Int32
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullInt32(t, badType, "wrong type json")
|
||||
|
||||
var invalid Int32
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullInt32(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonIntegerNumber32(t *testing.T) {
|
||||
var i Int32
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int32")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalInt32Overflow(t *testing.T) {
|
||||
int32Overflow := uint32(math.MaxInt32)
|
||||
|
||||
// Max int32 should decode successfully
|
||||
var i Int32
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(int32Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
int32Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(int32Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows int32")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalInt32(t *testing.T) {
|
||||
var i Int32
|
||||
err := i.UnmarshalText([]byte("2147483646"))
|
||||
maybePanic(err)
|
||||
assertInt32(t, i, "UnmarshalText() int32")
|
||||
|
||||
var blank Int32
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullInt32(t, blank, "UnmarshalText() empty int32")
|
||||
}
|
||||
|
||||
func TestMarshalInt32(t *testing.T) {
|
||||
i := Int32From(2147483646)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "2147483646", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt32(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalInt32Text(t *testing.T) {
|
||||
i := Int32From(2147483646)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "2147483646", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt32(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestInt32Pointer(t *testing.T) {
|
||||
i := Int32From(2147483646)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 2147483646 {
|
||||
t.Errorf("bad %s int32: %#v ≠ %d\n", "pointer", ptr, 2147483646)
|
||||
}
|
||||
|
||||
null := NewInt32(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int32: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32IsNull(t *testing.T) {
|
||||
i := Int32From(2147483646)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewInt32(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewInt32(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt32SetValid(t *testing.T) {
|
||||
change := NewInt32(0, false)
|
||||
assertNullInt32(t, change, "SetValid()")
|
||||
change.SetValid(2147483646)
|
||||
assertInt32(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestInt32Scan(t *testing.T) {
|
||||
var i Int32
|
||||
err := i.Scan(2147483646)
|
||||
maybePanic(err)
|
||||
assertInt32(t, i, "scanned int32")
|
||||
|
||||
var null Int32
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullInt32(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertInt32(t *testing.T, i Int32, from string) {
|
||||
if i.Int32 != 2147483646 {
|
||||
t.Errorf("bad %s int32: %d ≠ %d\n", from, i.Int32, 2147483646)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullInt32(t *testing.T, i Int32, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Int64 is an nullable int64.
|
||||
type Int64 struct {
|
||||
Int64 int64
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewInt64 creates a new Int64
|
||||
func NewInt64(i int64, valid bool) Int64 {
|
||||
return Int64{
|
||||
Int64: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Int64From creates a new Int64 that will always be valid.
|
||||
func Int64From(i int64) Int64 {
|
||||
return NewInt64(i, true)
|
||||
}
|
||||
|
||||
// Int64FromPtr creates a new Int64 that be null if i is nil.
|
||||
func Int64FromPtr(i *int64) Int64 {
|
||||
if i == nil {
|
||||
return NewInt64(0, false)
|
||||
}
|
||||
return NewInt64(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (i *Int64) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
i.Valid = false
|
||||
i.Int64 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &i.Int64); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (i *Int64) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
i.Int64, err = strconv.ParseInt(string(text), 10, 64)
|
||||
i.Valid = err == nil
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (i Int64) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(i.Int64, 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (i Int64) MarshalText() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(i.Int64, 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Int64's value and also sets it to be non-null.
|
||||
func (i *Int64) SetValid(n int64) {
|
||||
i.Int64 = n
|
||||
i.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Int64's value, or a nil pointer if this Int64 is null.
|
||||
func (i Int64) Ptr() *int64 {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
return &i.Int64
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Int64's, for future omitempty support (Go 1.4?)
|
||||
func (i Int64) IsNull() bool {
|
||||
return !i.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (i *Int64) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
i.Int64, i.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
i.Valid = true
|
||||
return convert.ConvertAssign(&i.Int64, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (i Int64) Value() (driver.Value, error) {
|
||||
if !i.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return i.Int64, nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
int64JSON = []byte(`9223372036854775806`)
|
||||
)
|
||||
|
||||
func TestInt64From(t *testing.T) {
|
||||
i := Int64From(9223372036854775806)
|
||||
assertInt64(t, i, "Int64From()")
|
||||
|
||||
zero := Int64From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Int64From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64FromPtr(t *testing.T) {
|
||||
n := int64(9223372036854775806)
|
||||
iptr := &n
|
||||
i := Int64FromPtr(iptr)
|
||||
assertInt64(t, i, "Int64FromPtr()")
|
||||
|
||||
null := Int64FromPtr(nil)
|
||||
assertNullInt64(t, null, "Int64FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalInt64(t *testing.T) {
|
||||
var i Int64
|
||||
err := json.Unmarshal(int64JSON, &i)
|
||||
maybePanic(err)
|
||||
assertInt64(t, i, "int64 json")
|
||||
|
||||
var null Int64
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullInt64(t, null, "null json")
|
||||
|
||||
var badType Int64
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullInt64(t, badType, "wrong type json")
|
||||
|
||||
var invalid Int64
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullInt64(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonIntegerNumber64(t *testing.T) {
|
||||
var i Int64
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int64")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalInt64Overflow(t *testing.T) {
|
||||
int64Overflow := uint64(math.MaxInt64)
|
||||
|
||||
// Max int64 should decode successfully
|
||||
var i Int64
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(int64Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
int64Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(int64Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows int64")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalInt64(t *testing.T) {
|
||||
var i Int64
|
||||
err := i.UnmarshalText([]byte("9223372036854775806"))
|
||||
maybePanic(err)
|
||||
assertInt64(t, i, "UnmarshalText() int64")
|
||||
|
||||
var blank Int64
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullInt64(t, blank, "UnmarshalText() empty int64")
|
||||
}
|
||||
|
||||
func TestMarshalInt64(t *testing.T) {
|
||||
i := Int64From(9223372036854775806)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "9223372036854775806", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt64(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalInt64Text(t *testing.T) {
|
||||
i := Int64From(9223372036854775806)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "9223372036854775806", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt64(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestInt64Pointer(t *testing.T) {
|
||||
i := Int64From(9223372036854775806)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 9223372036854775806 {
|
||||
t.Errorf("bad %s int64: %#v ≠ %d\n", "pointer", ptr, 9223372036854775806)
|
||||
}
|
||||
|
||||
null := NewInt64(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int64: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64IsNull(t *testing.T) {
|
||||
i := Int64From(9223372036854775806)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewInt64(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewInt64(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt64SetValid(t *testing.T) {
|
||||
change := NewInt64(0, false)
|
||||
assertNullInt64(t, change, "SetValid()")
|
||||
change.SetValid(9223372036854775806)
|
||||
assertInt64(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestInt64Scan(t *testing.T) {
|
||||
var i Int64
|
||||
err := i.Scan(9223372036854775806)
|
||||
maybePanic(err)
|
||||
assertInt64(t, i, "scanned int64")
|
||||
|
||||
var null Int64
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullInt64(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertInt64(t *testing.T, i Int64, from string) {
|
||||
if i.Int64 != 9223372036854775806 {
|
||||
t.Errorf("bad %s int64: %d ≠ %d\n", from, i.Int64, 9223372036854775806)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullInt64(t *testing.T, i Int64, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Int8 is an nullable int8.
|
||||
type Int8 struct {
|
||||
Int8 int8
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewInt8 creates a new Int8
|
||||
func NewInt8(i int8, valid bool) Int8 {
|
||||
return Int8{
|
||||
Int8: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Int8From creates a new Int8 that will always be valid.
|
||||
func Int8From(i int8) Int8 {
|
||||
return NewInt8(i, true)
|
||||
}
|
||||
|
||||
// Int8FromPtr creates a new Int8 that be null if i is nil.
|
||||
func Int8FromPtr(i *int8) Int8 {
|
||||
if i == nil {
|
||||
return NewInt8(0, false)
|
||||
}
|
||||
return NewInt8(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (i *Int8) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
i.Valid = false
|
||||
i.Int8 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x int64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxInt8 {
|
||||
return fmt.Errorf("json: %d overflows max int8 value", x)
|
||||
}
|
||||
|
||||
i.Int8 = int8(x)
|
||||
i.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (i *Int8) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
i.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseInt(string(text), 10, 8)
|
||||
i.Valid = err == nil
|
||||
if i.Valid {
|
||||
i.Int8 = int8(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (i Int8) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int8), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (i Int8) MarshalText() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatInt(int64(i.Int8), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Int8's value and also sets it to be non-null.
|
||||
func (i *Int8) SetValid(n int8) {
|
||||
i.Int8 = n
|
||||
i.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Int8's value, or a nil pointer if this Int8 is null.
|
||||
func (i Int8) Ptr() *int8 {
|
||||
if !i.Valid {
|
||||
return nil
|
||||
}
|
||||
return &i.Int8
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Int8's, for future omitempty support (Go 1.4?)
|
||||
func (i Int8) IsNull() bool {
|
||||
return !i.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (i *Int8) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
i.Int8, i.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
i.Valid = true
|
||||
return convert.ConvertAssign(&i.Int8, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (i Int8) Value() (driver.Value, error) {
|
||||
if !i.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(i.Int8), nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
int8JSON = []byte(`126`)
|
||||
)
|
||||
|
||||
func TestInt8From(t *testing.T) {
|
||||
i := Int8From(126)
|
||||
assertInt8(t, i, "Int8From()")
|
||||
|
||||
zero := Int8From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Int8From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt8FromPtr(t *testing.T) {
|
||||
n := int8(126)
|
||||
iptr := &n
|
||||
i := Int8FromPtr(iptr)
|
||||
assertInt8(t, i, "Int8FromPtr()")
|
||||
|
||||
null := Int8FromPtr(nil)
|
||||
assertNullInt8(t, null, "Int8FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalInt8(t *testing.T) {
|
||||
var i Int8
|
||||
err := json.Unmarshal(int8JSON, &i)
|
||||
maybePanic(err)
|
||||
assertInt8(t, i, "int8 json")
|
||||
|
||||
var null Int8
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullInt8(t, null, "null json")
|
||||
|
||||
var badType Int8
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullInt8(t, badType, "wrong type json")
|
||||
|
||||
var invalid Int8
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullInt8(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonIntegerNumber8(t *testing.T) {
|
||||
var i Int8
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int8")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalInt8Overflow(t *testing.T) {
|
||||
int8Overflow := uint8(math.MaxInt8)
|
||||
|
||||
// Max int8 should decode successfully
|
||||
var i Int8
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(int8Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
int8Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(int8Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows int8")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalInt8(t *testing.T) {
|
||||
var i Int8
|
||||
err := i.UnmarshalText([]byte("126"))
|
||||
maybePanic(err)
|
||||
assertInt8(t, i, "UnmarshalText() int8")
|
||||
|
||||
var blank Int8
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullInt8(t, blank, "UnmarshalText() empty int8")
|
||||
}
|
||||
|
||||
func TestMarshalInt8(t *testing.T) {
|
||||
i := Int8From(126)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "126", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt8(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalInt8Text(t *testing.T) {
|
||||
i := Int8From(126)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "126", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt8(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestInt8Pointer(t *testing.T) {
|
||||
i := Int8From(126)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 126 {
|
||||
t.Errorf("bad %s int8: %#v ≠ %d\n", "pointer", ptr, 126)
|
||||
}
|
||||
|
||||
null := NewInt8(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int8: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt8IsNull(t *testing.T) {
|
||||
i := Int8From(126)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewInt8(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewInt8(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInt8SetValid(t *testing.T) {
|
||||
change := NewInt8(0, false)
|
||||
assertNullInt8(t, change, "SetValid()")
|
||||
change.SetValid(126)
|
||||
assertInt8(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestInt8Scan(t *testing.T) {
|
||||
var i Int8
|
||||
err := i.Scan(126)
|
||||
maybePanic(err)
|
||||
assertInt8(t, i, "scanned int8")
|
||||
|
||||
var null Int8
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullInt8(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertInt8(t *testing.T, i Int8, from string) {
|
||||
if i.Int8 != 126 {
|
||||
t.Errorf("bad %s int8: %d ≠ %d\n", from, i.Int8, 126)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullInt8(t *testing.T, i Int8, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
intJSON = []byte(`12345`)
|
||||
)
|
||||
|
||||
func TestIntFrom(t *testing.T) {
|
||||
i := IntFrom(12345)
|
||||
assertInt(t, i, "IntFrom()")
|
||||
|
||||
zero := IntFrom(0)
|
||||
if !zero.Valid {
|
||||
t.Error("IntFrom(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntFromPtr(t *testing.T) {
|
||||
n := int(12345)
|
||||
iptr := &n
|
||||
i := IntFromPtr(iptr)
|
||||
assertInt(t, i, "IntFromPtr()")
|
||||
|
||||
null := IntFromPtr(nil)
|
||||
assertNullInt(t, null, "IntFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalInt(t *testing.T) {
|
||||
var i Int
|
||||
err := json.Unmarshal(intJSON, &i)
|
||||
maybePanic(err)
|
||||
assertInt(t, i, "int json")
|
||||
|
||||
var null Int
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullInt(t, null, "null json")
|
||||
|
||||
var badType Int
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullInt(t, badType, "wrong type json")
|
||||
|
||||
var invalid Int
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullInt(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonIntegerNumber(t *testing.T) {
|
||||
var i Int
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to int")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalInt(t *testing.T) {
|
||||
var i Int
|
||||
err := i.UnmarshalText([]byte("12345"))
|
||||
maybePanic(err)
|
||||
assertInt(t, i, "UnmarshalText() int")
|
||||
|
||||
var blank Int
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullInt(t, blank, "UnmarshalText() empty int")
|
||||
}
|
||||
|
||||
func TestMarshalInt(t *testing.T) {
|
||||
i := IntFrom(12345)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "12345", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalIntText(t *testing.T) {
|
||||
i := IntFrom(12345)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "12345", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewInt(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestIntPointer(t *testing.T) {
|
||||
i := IntFrom(12345)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 12345 {
|
||||
t.Errorf("bad %s int: %#v ≠ %d\n", "pointer", ptr, 12345)
|
||||
}
|
||||
|
||||
null := NewInt(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s int: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntIsNull(t *testing.T) {
|
||||
i := IntFrom(12345)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewInt(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewInt(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntSetValid(t *testing.T) {
|
||||
change := NewInt(0, false)
|
||||
assertNullInt(t, change, "SetValid()")
|
||||
change.SetValid(12345)
|
||||
assertInt(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestIntScan(t *testing.T) {
|
||||
var i Int
|
||||
err := i.Scan(12345)
|
||||
maybePanic(err)
|
||||
assertInt(t, i, "scanned int")
|
||||
|
||||
var null Int
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullInt(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertInt(t *testing.T, i Int, from string) {
|
||||
if i.Int != 12345 {
|
||||
t.Errorf("bad %s int: %d ≠ %d\n", from, i.Int, 12345)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullInt(t *testing.T, i Int, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// JSON is a nullable []byte.
|
||||
type JSON struct {
|
||||
JSON []byte
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewJSON creates a new JSON
|
||||
func NewJSON(b []byte, valid bool) JSON {
|
||||
return JSON{
|
||||
JSON: b,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// JSONFrom creates a new JSON that will be invalid if nil.
|
||||
func JSONFrom(b []byte) JSON {
|
||||
return NewJSON(b, b != nil)
|
||||
}
|
||||
|
||||
// JSONFromPtr creates a new JSON that will be invalid if nil.
|
||||
func JSONFromPtr(b *[]byte) JSON {
|
||||
if b == nil {
|
||||
return NewJSON(nil, false)
|
||||
}
|
||||
n := NewJSON(*b, true)
|
||||
return n
|
||||
}
|
||||
|
||||
// Unmarshal will unmarshal your JSON stored in
|
||||
// your JSON object and store the result in the
|
||||
// value pointed to by dest.
|
||||
func (j JSON) Unmarshal(dest interface{}) error {
|
||||
if dest == nil {
|
||||
return errors.New("destination is nil, not a valid pointer to an object")
|
||||
}
|
||||
|
||||
// Call our implementation of
|
||||
// JSON MarshalJSON through json.Marshal
|
||||
// to get the value of the JSON object
|
||||
res, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return json.Unmarshal(res, dest)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (j *JSON) UnmarshalJSON(data []byte) error {
|
||||
if data == nil {
|
||||
return fmt.Errorf("json: cannot unmarshal nil into Go value of type null.JSON")
|
||||
}
|
||||
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
j.JSON = NullBytes
|
||||
j.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
j.Valid = true
|
||||
j.JSON = make([]byte, len(data))
|
||||
copy(j.JSON, data)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (j *JSON) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
j.JSON = nil
|
||||
j.Valid = false
|
||||
} else {
|
||||
j.JSON = append(j.JSON[0:0], text...)
|
||||
j.Valid = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Marshal will marshal the passed in object,
|
||||
// and store it in the JSON member on the JSON object.
|
||||
func (j *JSON) Marshal(obj interface{}) error {
|
||||
res, err := json.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Call our implementation of
|
||||
// JSON UnmarshalJSON through json.Unmarshal
|
||||
// to set the result to the JSON object
|
||||
return json.Unmarshal(res, j)
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (j JSON) MarshalJSON() ([]byte, error) {
|
||||
if len(j.JSON) == 0 || j.JSON == nil {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return j.JSON, nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (j JSON) MarshalText() ([]byte, error) {
|
||||
if !j.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return j.JSON, nil
|
||||
}
|
||||
|
||||
// SetValid changes this JSON's value and also sets it to be non-null.
|
||||
func (j *JSON) SetValid(n []byte) {
|
||||
j.JSON = n
|
||||
j.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this JSON's value, or a nil pointer if this JSON is null.
|
||||
func (j JSON) Ptr() *[]byte {
|
||||
if !j.Valid {
|
||||
return nil
|
||||
}
|
||||
return &j.JSON
|
||||
}
|
||||
|
||||
// IsNull returns true for null or zero JSON's, for future omitempty support (Go 1.4?)
|
||||
func (j JSON) IsNull() bool {
|
||||
return !j.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (j *JSON) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
j.JSON, j.Valid = []byte{}, false
|
||||
return nil
|
||||
}
|
||||
j.Valid = true
|
||||
return convert.ConvertAssign(&j.JSON, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (j JSON) Value() (driver.Value, error) {
|
||||
if !j.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return j.JSON, nil
|
||||
}
|
||||
@@ -1,238 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
jsonJSON = []byte(`"hello"`)
|
||||
)
|
||||
|
||||
func TestJSONFrom(t *testing.T) {
|
||||
i := JSONFrom([]byte(`"hello"`))
|
||||
assertJSON(t, i, "JSONFrom()")
|
||||
|
||||
zero := JSONFrom(nil)
|
||||
if zero.Valid {
|
||||
t.Error("JSONFrom(nil)", "is valid, but should be invalid")
|
||||
}
|
||||
|
||||
zero = JSONFrom([]byte{})
|
||||
if !zero.Valid {
|
||||
t.Error("JSONFrom([]byte{})", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONFromPtr(t *testing.T) {
|
||||
n := []byte(`"hello"`)
|
||||
iptr := &n
|
||||
i := JSONFromPtr(iptr)
|
||||
assertJSON(t, i, "JSONFromPtr()")
|
||||
|
||||
null := JSONFromPtr(nil)
|
||||
assertNullJSON(t, null, "JSONFromPtr(nil)")
|
||||
}
|
||||
|
||||
type Test struct {
|
||||
Name string
|
||||
Age int
|
||||
}
|
||||
|
||||
func TestMarshal(t *testing.T) {
|
||||
var i JSON
|
||||
|
||||
test := &Test{Name: "hello", Age: 15}
|
||||
|
||||
err := i.Marshal(test)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(i.JSON, []byte(`{"Name":"hello","Age":15}`)) {
|
||||
t.Errorf("Mismatch between received and expected, got: %s", string(i.JSON))
|
||||
}
|
||||
if i.Valid == false {
|
||||
t.Error("Expected valid true, got Valid false")
|
||||
}
|
||||
|
||||
err = i.Marshal(nil)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(i.JSON, []byte("null")) {
|
||||
t.Errorf("Expected null, but got %s", string(i.JSON))
|
||||
}
|
||||
if i.Valid == true {
|
||||
t.Error("Expected Valid false, got Valid true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshal(t *testing.T) {
|
||||
var i JSON
|
||||
|
||||
test := &Test{}
|
||||
|
||||
err := i.Unmarshal(test)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
x := &Test{Name: "hello", Age: 15}
|
||||
err = i.Marshal(x)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if !bytes.Equal(i.JSON, []byte(`{"Name":"hello","Age":15}`)) {
|
||||
t.Errorf("Mismatch between received and expected, got: %s", string(i.JSON))
|
||||
}
|
||||
|
||||
err = i.Unmarshal(test)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if test.Age != 15 {
|
||||
t.Errorf("Expected 15, got %d", test.Age)
|
||||
}
|
||||
if test.Name != "hello" {
|
||||
t.Errorf("Expected name, got %s", test.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalJSON(t *testing.T) {
|
||||
var i JSON
|
||||
err := json.Unmarshal(jsonJSON, &i)
|
||||
maybePanic(err)
|
||||
assertJSON(t, i, "[]byte json")
|
||||
|
||||
var ni JSON
|
||||
err = ni.UnmarshalJSON([]byte{})
|
||||
if ni.Valid == false {
|
||||
t.Errorf("expected Valid to be true, got false")
|
||||
}
|
||||
if !bytes.Equal(ni.JSON, nil) {
|
||||
t.Errorf("Expected JSON to be nil, but was not: %#v %#v", ni.JSON, []byte(nil))
|
||||
}
|
||||
|
||||
var null JSON
|
||||
err = null.UnmarshalJSON(nil)
|
||||
if ni.Valid == false {
|
||||
t.Errorf("expected Valid to be true, got false")
|
||||
}
|
||||
if !bytes.Equal(null.JSON, nil) {
|
||||
t.Errorf("Expected JSON to be []byte nil, but was not: %#v %#v", null.JSON, []byte(nil))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalJSON(t *testing.T) {
|
||||
var i JSON
|
||||
err := i.UnmarshalText([]byte(`"hello"`))
|
||||
maybePanic(err)
|
||||
assertJSON(t, i, "UnmarshalText() []byte")
|
||||
|
||||
var blank JSON
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullJSON(t, blank, "UnmarshalText() empty []byte")
|
||||
}
|
||||
|
||||
func TestMarshalJSON(t *testing.T) {
|
||||
i := JSONFrom([]byte(`"hello"`))
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"hello"`, "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewJSON(nil, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalJSONText(t *testing.T) {
|
||||
i := JSONFrom([]byte(`"hello"`))
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"hello"`, "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewJSON(nil, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestJSONPointer(t *testing.T) {
|
||||
i := JSONFrom([]byte(`"hello"`))
|
||||
ptr := i.Ptr()
|
||||
if !bytes.Equal(*ptr, []byte(`"hello"`)) {
|
||||
t.Errorf("bad %s []byte: %#v ≠ %s\n", "pointer", ptr, `"hello"`)
|
||||
}
|
||||
|
||||
null := NewJSON(nil, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s []byte: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONIsNull(t *testing.T) {
|
||||
i := JSONFrom([]byte(`"hello"`))
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewJSON(nil, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewJSON(nil, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestJSONSetValid(t *testing.T) {
|
||||
change := NewJSON(nil, false)
|
||||
assertNullJSON(t, change, "SetValid()")
|
||||
change.SetValid([]byte(`"hello"`))
|
||||
assertJSON(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestJSONScan(t *testing.T) {
|
||||
var i JSON
|
||||
err := i.Scan(`"hello"`)
|
||||
maybePanic(err)
|
||||
assertJSON(t, i, "scanned []byte")
|
||||
|
||||
var null JSON
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullJSON(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertJSON(t *testing.T, i JSON, from string) {
|
||||
if !bytes.Equal(i.JSON, []byte(`"hello"`)) {
|
||||
t.Errorf("bad %s []byte: %#v ≠ %#v\n", from, string(i.JSON), string([]byte(`"hello"`)))
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullJSON(t *testing.T, i JSON, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package null
|
||||
|
||||
type Nullable interface {
|
||||
IsNull() bool
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// String is a nullable string. It supports SQL and JSON serialization.
|
||||
type String struct {
|
||||
String string
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// StringFrom creates a new String that will never be blank.
|
||||
func StringFrom(s string) String {
|
||||
return NewString(s, true)
|
||||
}
|
||||
|
||||
// StringFromPtr creates a new String that be null if s is nil.
|
||||
func StringFromPtr(s *string) String {
|
||||
if s == nil {
|
||||
return NewString("", false)
|
||||
}
|
||||
return NewString(*s, true)
|
||||
}
|
||||
|
||||
// NewString creates a new String
|
||||
func NewString(s string, valid bool) String {
|
||||
return String{
|
||||
String: s,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (s *String) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
s.String = ""
|
||||
s.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &s.String); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (s String) MarshalJSON() ([]byte, error) {
|
||||
if !s.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return json.Marshal(s.String)
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (s String) MarshalText() ([]byte, error) {
|
||||
if !s.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(s.String), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (s *String) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
s.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
s.String = string(text)
|
||||
s.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetValid changes this String's value and also sets it to be non-null.
|
||||
func (s *String) SetValid(v string) {
|
||||
s.String = v
|
||||
s.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this String's value, or a nil pointer if this String is null.
|
||||
func (s String) Ptr() *string {
|
||||
if !s.Valid {
|
||||
return nil
|
||||
}
|
||||
return &s.String
|
||||
}
|
||||
|
||||
// IsNull returns true for null strings, for potential future omitempty support.
|
||||
func (s String) IsNull() bool {
|
||||
return !s.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (s *String) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
s.String, s.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
s.Valid = true
|
||||
return convert.ConvertAssign(&s.String, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (s String) Value() (driver.Value, error) {
|
||||
if !s.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return s.String, nil
|
||||
}
|
||||
@@ -1,206 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
stringJSON = []byte(`"test"`)
|
||||
blankStringJSON = []byte(`""`)
|
||||
|
||||
nullJSON = []byte(`null`)
|
||||
invalidJSON = []byte(`:)`)
|
||||
)
|
||||
|
||||
type stringInStruct struct {
|
||||
Test String `json:"test,omitempty"`
|
||||
}
|
||||
|
||||
func TestStringFrom(t *testing.T) {
|
||||
str := StringFrom("test")
|
||||
assertStr(t, str, "StringFrom() string")
|
||||
|
||||
zero := StringFrom("")
|
||||
if !zero.Valid {
|
||||
t.Error("StringFrom(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringFromPtr(t *testing.T) {
|
||||
s := "test"
|
||||
sptr := &s
|
||||
str := StringFromPtr(sptr)
|
||||
assertStr(t, str, "StringFromPtr() string")
|
||||
|
||||
null := StringFromPtr(nil)
|
||||
assertNullStr(t, null, "StringFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalString(t *testing.T) {
|
||||
var str String
|
||||
err := json.Unmarshal(stringJSON, &str)
|
||||
maybePanic(err)
|
||||
assertStr(t, str, "string json")
|
||||
|
||||
var blank String
|
||||
err = json.Unmarshal(blankStringJSON, &blank)
|
||||
maybePanic(err)
|
||||
if !blank.Valid {
|
||||
t.Error("blank string should be valid")
|
||||
}
|
||||
|
||||
var null String
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullStr(t, null, "null json")
|
||||
|
||||
var badType String
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullStr(t, badType, "wrong type json")
|
||||
|
||||
var invalid String
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullStr(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestTextUnmarshalString(t *testing.T) {
|
||||
var str String
|
||||
err := str.UnmarshalText([]byte("test"))
|
||||
maybePanic(err)
|
||||
assertStr(t, str, "UnmarshalText() string")
|
||||
|
||||
var null String
|
||||
err = null.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullStr(t, null, "UnmarshalText() empty string")
|
||||
}
|
||||
|
||||
func TestMarshalString(t *testing.T) {
|
||||
str := StringFrom("test")
|
||||
data, err := json.Marshal(str)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `"test"`, "non-empty json marshal")
|
||||
data, err = str.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "test", "non-empty text marshal")
|
||||
|
||||
// empty values should be encoded as an empty string
|
||||
zero := StringFrom("")
|
||||
data, err = json.Marshal(zero)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `""`, "empty json marshal")
|
||||
data, err = zero.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "string marshal text")
|
||||
|
||||
null := StringFromPtr(nil)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, `null`, "null json marshal")
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "string marshal text")
|
||||
}
|
||||
|
||||
// Tests omitempty... broken until Go 1.4
|
||||
// func TestMarshalStringInStruct(t *testing.T) {
|
||||
// obj := stringInStruct{Test: StringFrom("")}
|
||||
// data, err := json.Marshal(obj)
|
||||
// maybePanic(err)
|
||||
// assertJSONEquals(t, data, `{}`, "null string in struct")
|
||||
// }
|
||||
|
||||
func TestStringPointer(t *testing.T) {
|
||||
str := StringFrom("test")
|
||||
ptr := str.Ptr()
|
||||
if *ptr != "test" {
|
||||
t.Errorf("bad %s string: %#v ≠ %s\n", "pointer", ptr, "test")
|
||||
}
|
||||
|
||||
null := NewString("", false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s string: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringIsNull(t *testing.T) {
|
||||
str := StringFrom("test")
|
||||
if str.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
blank := StringFrom("")
|
||||
if blank.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
empty := NewString("", true)
|
||||
if empty.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := StringFromPtr(nil)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = empty
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSetValid(t *testing.T) {
|
||||
change := NewString("", false)
|
||||
assertNullStr(t, change, "SetValid()")
|
||||
change.SetValid("test")
|
||||
assertStr(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestStringScan(t *testing.T) {
|
||||
var str String
|
||||
err := str.Scan("test")
|
||||
maybePanic(err)
|
||||
assertStr(t, str, "scanned string")
|
||||
|
||||
var null String
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullStr(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func maybePanic(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func assertStr(t *testing.T, s String, from string) {
|
||||
if s.String != "test" {
|
||||
t.Errorf("bad %s string: %s ≠ %s\n", from, s.String, "test")
|
||||
}
|
||||
if !s.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullStr(t *testing.T, s String, from string) {
|
||||
if s.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertJSONEquals(t *testing.T, data []byte, cmp string, from string) {
|
||||
if string(data) != cmp {
|
||||
t.Errorf("bad %s data: %s ≠ %s\n", from, data, cmp)
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Time is a nullable time.Time. It supports SQL and JSON serialization.
|
||||
type Time struct {
|
||||
Time time.Time
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewTime creates a new Time.
|
||||
func NewTime(t time.Time, valid bool) Time {
|
||||
return Time{
|
||||
Time: t,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// TimeFrom creates a new Time that will always be valid.
|
||||
func TimeFrom(t time.Time) Time {
|
||||
return NewTime(t, true)
|
||||
}
|
||||
|
||||
// TimeFromPtr creates a new Time that will be null if t is nil.
|
||||
func TimeFromPtr(t *time.Time) Time {
|
||||
if t == nil {
|
||||
return NewTime(time.Time{}, false)
|
||||
}
|
||||
return NewTime(*t, true)
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (t Time) MarshalJSON() ([]byte, error) {
|
||||
if !t.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return t.Time.MarshalJSON()
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (t *Time) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
t.Valid = false
|
||||
t.Time = time.Time{}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := t.Time.UnmarshalJSON(data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (t Time) MarshalText() ([]byte, error) {
|
||||
if !t.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return t.Time.MarshalText()
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (t *Time) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
t.Valid = false
|
||||
return nil
|
||||
}
|
||||
if err := t.Time.UnmarshalText(text); err != nil {
|
||||
return err
|
||||
}
|
||||
t.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetValid changes this Time's value and sets it to be non-null.
|
||||
func (t *Time) SetValid(v time.Time) {
|
||||
t.Time = v
|
||||
t.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Time's value, or a nil pointer if this Time is null.
|
||||
func (t Time) Ptr() *time.Time {
|
||||
if !t.Valid {
|
||||
return nil
|
||||
}
|
||||
return &t.Time
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Times, for future omitempty support (Go 1.4?)
|
||||
func (t Time) IsNull() bool {
|
||||
return !t.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (t *Time) Scan(value interface{}) error {
|
||||
var err error
|
||||
switch x := value.(type) {
|
||||
case time.Time:
|
||||
t.Time = x
|
||||
case nil:
|
||||
t.Valid = false
|
||||
return nil
|
||||
default:
|
||||
err = fmt.Errorf("null: cannot scan type %T into null.Time: %v", value, value)
|
||||
}
|
||||
t.Valid = err == nil
|
||||
return err
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (t Time) Value() (driver.Value, error) {
|
||||
if !t.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return t.Time, nil
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
timeString = "2012-12-21T21:21:21Z"
|
||||
timeJSON = []byte(`"` + timeString + `"`)
|
||||
nullTimeJSON = []byte(`null`)
|
||||
timeValue, _ = time.Parse(time.RFC3339, timeString)
|
||||
badObject = []byte(`{"hello": "world"}`)
|
||||
)
|
||||
|
||||
func TestUnmarshalTimeJSON(t *testing.T) {
|
||||
var ti Time
|
||||
err := json.Unmarshal(timeJSON, &ti)
|
||||
maybePanic(err)
|
||||
assertTime(t, ti, "UnmarshalJSON() json")
|
||||
|
||||
var null Time
|
||||
err = json.Unmarshal(nullTimeJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullTime(t, null, "null time json")
|
||||
|
||||
var invalid Time
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*time.ParseError); !ok {
|
||||
t.Errorf("expected json.ParseError, not %T", err)
|
||||
}
|
||||
assertNullTime(t, invalid, "invalid from object json")
|
||||
|
||||
var bad Time
|
||||
err = json.Unmarshal(badObject, &bad)
|
||||
if err == nil {
|
||||
t.Errorf("expected error: bad object")
|
||||
}
|
||||
assertNullTime(t, bad, "bad from object json")
|
||||
|
||||
var wrongType Time
|
||||
err = json.Unmarshal(intJSON, &wrongType)
|
||||
if err == nil {
|
||||
t.Errorf("expected error: wrong type JSON")
|
||||
}
|
||||
assertNullTime(t, wrongType, "wrong type object json")
|
||||
}
|
||||
|
||||
func TestUnmarshalTimeText(t *testing.T) {
|
||||
ti := TimeFrom(timeValue)
|
||||
txt, err := ti.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, txt, timeString, "marshal text")
|
||||
|
||||
var unmarshal Time
|
||||
err = unmarshal.UnmarshalText(txt)
|
||||
maybePanic(err)
|
||||
assertTime(t, unmarshal, "unmarshal text")
|
||||
|
||||
var invalid Time
|
||||
err = invalid.UnmarshalText([]byte("hello world"))
|
||||
if err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
assertNullTime(t, invalid, "bad string")
|
||||
}
|
||||
|
||||
func TestMarshalTime(t *testing.T) {
|
||||
ti := TimeFrom(timeValue)
|
||||
data, err := json.Marshal(ti)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, string(timeJSON), "non-empty json marshal")
|
||||
|
||||
ti.Valid = false
|
||||
data, err = json.Marshal(ti)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, string(nullJSON), "null json marshal")
|
||||
}
|
||||
|
||||
func TestTimeFrom(t *testing.T) {
|
||||
ti := TimeFrom(timeValue)
|
||||
assertTime(t, ti, "TimeFrom() time.Time")
|
||||
}
|
||||
|
||||
func TestTimeFromPtr(t *testing.T) {
|
||||
ti := TimeFromPtr(&timeValue)
|
||||
assertTime(t, ti, "TimeFromPtr() time")
|
||||
|
||||
null := TimeFromPtr(nil)
|
||||
assertNullTime(t, null, "TimeFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestTimeSetValid(t *testing.T) {
|
||||
var ti time.Time
|
||||
change := NewTime(ti, false)
|
||||
assertNullTime(t, change, "SetValid()")
|
||||
change.SetValid(timeValue)
|
||||
assertTime(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestTimeIsNull(t *testing.T) {
|
||||
ti := TimeFrom(time.Now())
|
||||
if ti.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewTime(time.Now(), false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewTime(time.Time{}, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimePointer(t *testing.T) {
|
||||
ti := TimeFrom(timeValue)
|
||||
ptr := ti.Ptr()
|
||||
if *ptr != timeValue {
|
||||
t.Errorf("bad %s time: %#v ≠ %v\n", "pointer", ptr, timeValue)
|
||||
}
|
||||
|
||||
var nt time.Time
|
||||
null := NewTime(nt, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s time: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeScanValue(t *testing.T) {
|
||||
var ti Time
|
||||
err := ti.Scan(timeValue)
|
||||
maybePanic(err)
|
||||
assertTime(t, ti, "scanned time")
|
||||
if v, err := ti.Value(); v != timeValue || err != nil {
|
||||
t.Error("bad value or err:", v, err)
|
||||
}
|
||||
|
||||
var null Time
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullTime(t, null, "scanned null")
|
||||
if v, err := null.Value(); v != nil || err != nil {
|
||||
t.Error("bad value or err:", v, err)
|
||||
}
|
||||
|
||||
var wrong Time
|
||||
err = wrong.Scan(int64(42))
|
||||
if err == nil {
|
||||
t.Error("expected error")
|
||||
}
|
||||
assertNullTime(t, wrong, "scanned wrong")
|
||||
}
|
||||
|
||||
func assertTime(t *testing.T, ti Time, from string) {
|
||||
if ti.Time != timeValue {
|
||||
t.Errorf("bad %v time: %v ≠ %v\n", from, ti.Time, timeValue)
|
||||
}
|
||||
if !ti.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullTime(t *testing.T, ti Time, from string) {
|
||||
if ti.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Uint is an nullable uint.
|
||||
type Uint struct {
|
||||
Uint uint
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewUint creates a new Uint
|
||||
func NewUint(i uint, valid bool) Uint {
|
||||
return Uint{
|
||||
Uint: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// UintFrom creates a new Uint that will always be valid.
|
||||
func UintFrom(i uint) Uint {
|
||||
return NewUint(i, true)
|
||||
}
|
||||
|
||||
// UintFromPtr creates a new Uint that be null if i is nil.
|
||||
func UintFromPtr(i *uint) Uint {
|
||||
if i == nil {
|
||||
return NewUint(0, false)
|
||||
}
|
||||
return NewUint(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *Uint) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
u.Valid = false
|
||||
u.Uint = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x uint64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Uint = uint(x)
|
||||
u.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (u *Uint) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseUint(string(text), 10, 0)
|
||||
u.Valid = err == nil
|
||||
if u.Valid {
|
||||
u.Uint = uint(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u Uint) MarshalJSON() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (u Uint) MarshalText() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Uint's value and also sets it to be non-null.
|
||||
func (u *Uint) SetValid(n uint) {
|
||||
u.Uint = n
|
||||
u.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Uint's value, or a nil pointer if this Uint is null.
|
||||
func (u Uint) Ptr() *uint {
|
||||
if !u.Valid {
|
||||
return nil
|
||||
}
|
||||
return &u.Uint
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Uints, for future omitempty support (Go 1.4?)
|
||||
func (u Uint) IsNull() bool {
|
||||
return !u.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (u *Uint) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
u.Uint, u.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
u.Valid = true
|
||||
return convert.ConvertAssign(&u.Uint, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (u Uint) Value() (driver.Value, error) {
|
||||
if !u.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(u.Uint), nil
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Uint16 is an nullable uint16.
|
||||
type Uint16 struct {
|
||||
Uint16 uint16
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewUint16 creates a new Uint16
|
||||
func NewUint16(i uint16, valid bool) Uint16 {
|
||||
return Uint16{
|
||||
Uint16: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Uint16From creates a new Uint16 that will always be valid.
|
||||
func Uint16From(i uint16) Uint16 {
|
||||
return NewUint16(i, true)
|
||||
}
|
||||
|
||||
// Uint16FromPtr creates a new Uint16 that be null if i is nil.
|
||||
func Uint16FromPtr(i *uint16) Uint16 {
|
||||
if i == nil {
|
||||
return NewUint16(0, false)
|
||||
}
|
||||
return NewUint16(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *Uint16) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
u.Valid = false
|
||||
u.Uint16 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x uint64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxUint16 {
|
||||
return fmt.Errorf("json: %d overflows max uint8 value", x)
|
||||
}
|
||||
|
||||
u.Uint16 = uint16(x)
|
||||
u.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (u *Uint16) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseUint(string(text), 10, 16)
|
||||
u.Valid = err == nil
|
||||
if u.Valid {
|
||||
u.Uint16 = uint16(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u Uint16) MarshalJSON() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint16), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (u Uint16) MarshalText() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint16), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Uint16's value and also sets it to be non-null.
|
||||
func (u *Uint16) SetValid(n uint16) {
|
||||
u.Uint16 = n
|
||||
u.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Uint16's value, or a nil pointer if this Uint16 is null.
|
||||
func (u Uint16) Ptr() *uint16 {
|
||||
if !u.Valid {
|
||||
return nil
|
||||
}
|
||||
return &u.Uint16
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Uint16's, for future omitempty support (Go 1.4?)
|
||||
func (u Uint16) IsNull() bool {
|
||||
return !u.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (u *Uint16) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
u.Uint16, u.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
u.Valid = true
|
||||
return convert.ConvertAssign(&u.Uint16, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (u Uint16) Value() (driver.Value, error) {
|
||||
if !u.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(u.Uint16), nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
uint16JSON = []byte(`65534`)
|
||||
)
|
||||
|
||||
func TestUint16From(t *testing.T) {
|
||||
i := Uint16From(65534)
|
||||
assertUint16(t, i, "Uint16From()")
|
||||
|
||||
zero := Uint16From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Uint16From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint16FromPtr(t *testing.T) {
|
||||
n := uint16(65534)
|
||||
iptr := &n
|
||||
i := Uint16FromPtr(iptr)
|
||||
assertUint16(t, i, "Uint16FromPtr()")
|
||||
|
||||
null := Uint16FromPtr(nil)
|
||||
assertNullUint16(t, null, "Uint16FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalUint16(t *testing.T) {
|
||||
var i Uint16
|
||||
err := json.Unmarshal(uint16JSON, &i)
|
||||
maybePanic(err)
|
||||
assertUint16(t, i, "uint16 json")
|
||||
|
||||
var null Uint16
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullUint16(t, null, "null json")
|
||||
|
||||
var badType Uint16
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullUint16(t, badType, "wrong type json")
|
||||
|
||||
var invalid Uint16
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullUint16(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonUintegerNumber16(t *testing.T) {
|
||||
var i Uint16
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to uint16")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUint16Overflow(t *testing.T) {
|
||||
uint16Overflow := int64(math.MaxUint16)
|
||||
|
||||
// Max uint16 should decode successfully
|
||||
var i Uint16
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(uint16Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
uint16Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(uint16Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows uint16")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalUint16(t *testing.T) {
|
||||
var i Uint16
|
||||
err := i.UnmarshalText([]byte("65534"))
|
||||
maybePanic(err)
|
||||
assertUint16(t, i, "UnmarshalText() uint16")
|
||||
|
||||
var blank Uint16
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullUint16(t, blank, "UnmarshalText() empty uint16")
|
||||
}
|
||||
|
||||
func TestMarshalUint16(t *testing.T) {
|
||||
i := Uint16From(65534)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "65534", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint16(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalUint16Text(t *testing.T) {
|
||||
i := Uint16From(65534)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "65534", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint16(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestUint16Pointer(t *testing.T) {
|
||||
i := Uint16From(65534)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 65534 {
|
||||
t.Errorf("bad %s uint16: %#v ≠ %d\n", "pointer", ptr, 65534)
|
||||
}
|
||||
|
||||
null := NewUint16(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s uint16: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint16IsNull(t *testing.T) {
|
||||
i := Uint16From(65534)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewUint16(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewUint16(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint16SetValid(t *testing.T) {
|
||||
change := NewUint16(0, false)
|
||||
assertNullUint16(t, change, "SetValid()")
|
||||
change.SetValid(65534)
|
||||
assertUint16(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestUint16Scan(t *testing.T) {
|
||||
var i Uint16
|
||||
err := i.Scan(65534)
|
||||
maybePanic(err)
|
||||
assertUint16(t, i, "scanned uint16")
|
||||
|
||||
var null Uint16
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullUint16(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertUint16(t *testing.T, i Uint16, from string) {
|
||||
if i.Uint16 != 65534 {
|
||||
t.Errorf("bad %s uint16: %d ≠ %d\n", from, i.Uint16, 65534)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullUint16(t *testing.T, i Uint16, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Uint32 is an nullable uint32.
|
||||
type Uint32 struct {
|
||||
Uint32 uint32
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewUint32 creates a new Uint32
|
||||
func NewUint32(i uint32, valid bool) Uint32 {
|
||||
return Uint32{
|
||||
Uint32: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Uint32From creates a new Uint32 that will always be valid.
|
||||
func Uint32From(i uint32) Uint32 {
|
||||
return NewUint32(i, true)
|
||||
}
|
||||
|
||||
// Uint32FromPtr creates a new Uint32 that be null if i is nil.
|
||||
func Uint32FromPtr(i *uint32) Uint32 {
|
||||
if i == nil {
|
||||
return NewUint32(0, false)
|
||||
}
|
||||
return NewUint32(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *Uint32) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
u.Valid = false
|
||||
u.Uint32 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x uint64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxUint32 {
|
||||
return fmt.Errorf("json: %d overflows max uint32 value", x)
|
||||
}
|
||||
|
||||
u.Uint32 = uint32(x)
|
||||
u.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (u *Uint32) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseUint(string(text), 10, 32)
|
||||
u.Valid = err == nil
|
||||
if u.Valid {
|
||||
u.Uint32 = uint32(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u Uint32) MarshalJSON() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint32), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (u Uint32) MarshalText() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint32), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Uint32's value and also sets it to be non-null.
|
||||
func (u *Uint32) SetValid(n uint32) {
|
||||
u.Uint32 = n
|
||||
u.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Uint32's value, or a nil pointer if this Uint32 is null.
|
||||
func (u Uint32) Ptr() *uint32 {
|
||||
if !u.Valid {
|
||||
return nil
|
||||
}
|
||||
return &u.Uint32
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Uint32's, for future omitempty support (Go 1.4?)
|
||||
func (u Uint32) IsNull() bool {
|
||||
return !u.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (u *Uint32) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
u.Uint32, u.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
u.Valid = true
|
||||
return convert.ConvertAssign(&u.Uint32, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (u Uint32) Value() (driver.Value, error) {
|
||||
if !u.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return uint64(u.Uint32), nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
uint32JSON = []byte(`4294967294`)
|
||||
)
|
||||
|
||||
func TestUint32From(t *testing.T) {
|
||||
i := Uint32From(4294967294)
|
||||
assertUint32(t, i, "Uint32From()")
|
||||
|
||||
zero := Uint32From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Uint32From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint32FromPtr(t *testing.T) {
|
||||
n := uint32(4294967294)
|
||||
iptr := &n
|
||||
i := Uint32FromPtr(iptr)
|
||||
assertUint32(t, i, "Uint32FromPtr()")
|
||||
|
||||
null := Uint32FromPtr(nil)
|
||||
assertNullUint32(t, null, "Uint32FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalUint32(t *testing.T) {
|
||||
var i Uint32
|
||||
err := json.Unmarshal(uint32JSON, &i)
|
||||
maybePanic(err)
|
||||
assertUint32(t, i, "uint32 json")
|
||||
|
||||
var null Uint32
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullUint32(t, null, "null json")
|
||||
|
||||
var badType Uint32
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullUint32(t, badType, "wrong type json")
|
||||
|
||||
var invalid Uint32
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullUint32(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonUintegerNumber32(t *testing.T) {
|
||||
var i Uint32
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to uint32")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUint32Overflow(t *testing.T) {
|
||||
uint32Overflow := int64(math.MaxUint32)
|
||||
|
||||
// Max uint32 should decode successfully
|
||||
var i Uint32
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(uint32Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
uint32Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(uint32Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows uint32")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalUint32(t *testing.T) {
|
||||
var i Uint32
|
||||
err := i.UnmarshalText([]byte("4294967294"))
|
||||
maybePanic(err)
|
||||
assertUint32(t, i, "UnmarshalText() uint32")
|
||||
|
||||
var blank Uint32
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullUint32(t, blank, "UnmarshalText() empty uint32")
|
||||
}
|
||||
|
||||
func TestMarshalUint32(t *testing.T) {
|
||||
i := Uint32From(4294967294)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "4294967294", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint32(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalUint32Text(t *testing.T) {
|
||||
i := Uint32From(4294967294)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "4294967294", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint32(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestUint32Pointer(t *testing.T) {
|
||||
i := Uint32From(4294967294)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 4294967294 {
|
||||
t.Errorf("bad %s uint32: %#v ≠ %d\n", "pointer", ptr, 4294967294)
|
||||
}
|
||||
|
||||
null := NewUint32(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s uint32: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint32IsNull(t *testing.T) {
|
||||
i := Uint32From(4294967294)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewUint32(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewUint32(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint32SetValid(t *testing.T) {
|
||||
change := NewUint32(0, false)
|
||||
assertNullUint32(t, change, "SetValid()")
|
||||
change.SetValid(4294967294)
|
||||
assertUint32(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestUint32Scan(t *testing.T) {
|
||||
var i Uint32
|
||||
err := i.Scan(4294967294)
|
||||
maybePanic(err)
|
||||
assertUint32(t, i, "scanned uint32")
|
||||
|
||||
var null Uint32
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullUint32(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertUint32(t *testing.T, i Uint32, from string) {
|
||||
if i.Uint32 != 4294967294 {
|
||||
t.Errorf("bad %s uint32: %d ≠ %d\n", from, i.Uint32, 4294967294)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullUint32(t *testing.T, i Uint32, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Uint64 is an nullable uint64.
|
||||
type Uint64 struct {
|
||||
Uint64 uint64
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewUint64 creates a new Uint64
|
||||
func NewUint64(i uint64, valid bool) Uint64 {
|
||||
return Uint64{
|
||||
Uint64: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Uint64From creates a new Uint64 that will always be valid.
|
||||
func Uint64From(i uint64) Uint64 {
|
||||
return NewUint64(i, true)
|
||||
}
|
||||
|
||||
// Uint64FromPtr creates a new Uint64 that be null if i is nil.
|
||||
func Uint64FromPtr(i *uint64) Uint64 {
|
||||
if i == nil {
|
||||
return NewUint64(0, false)
|
||||
}
|
||||
return NewUint64(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *Uint64) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
u.Uint64 = 0
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &u.Uint64); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (u *Uint64) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseUint(string(text), 10, 64)
|
||||
u.Valid = err == nil
|
||||
if u.Valid {
|
||||
u.Uint64 = uint64(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u Uint64) MarshalJSON() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(u.Uint64, 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (u Uint64) MarshalText() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(u.Uint64, 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Uint64's value and also sets it to be non-null.
|
||||
func (u *Uint64) SetValid(n uint64) {
|
||||
u.Uint64 = n
|
||||
u.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Uint64's value, or a nil pointer if this Uint64 is null.
|
||||
func (u Uint64) Ptr() *uint64 {
|
||||
if !u.Valid {
|
||||
return nil
|
||||
}
|
||||
return &u.Uint64
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Uint64's, for future omitempty support (Go 1.4?)
|
||||
func (u Uint64) IsNull() bool {
|
||||
return !u.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (u *Uint64) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
u.Uint64, u.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
u.Valid = true
|
||||
return convert.ConvertAssign(&u.Uint64, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (u Uint64) Value() (driver.Value, error) {
|
||||
if !u.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(u.Uint64), nil
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
uint64JSON = []byte(`18446744073709551614`)
|
||||
)
|
||||
|
||||
func TestUint64From(t *testing.T) {
|
||||
i := Uint64From(18446744073709551614)
|
||||
assertUint64(t, i, "Uint64From()")
|
||||
|
||||
zero := Uint64From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Uint64From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint64FromPtr(t *testing.T) {
|
||||
n := uint64(18446744073709551614)
|
||||
iptr := &n
|
||||
i := Uint64FromPtr(iptr)
|
||||
assertUint64(t, i, "Uint64FromPtr()")
|
||||
|
||||
null := Uint64FromPtr(nil)
|
||||
assertNullUint64(t, null, "Uint64FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalUint64(t *testing.T) {
|
||||
var i Uint64
|
||||
err := json.Unmarshal(uint64JSON, &i)
|
||||
maybePanic(err)
|
||||
assertUint64(t, i, "uint64 json")
|
||||
|
||||
var null Uint64
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullUint64(t, null, "null json")
|
||||
|
||||
var badType Uint64
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullUint64(t, badType, "wrong type json")
|
||||
|
||||
var invalid Uint64
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullUint64(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonUintegerNumber64(t *testing.T) {
|
||||
var i Uint64
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to uint64")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalUint64(t *testing.T) {
|
||||
var i Uint64
|
||||
err := i.UnmarshalText([]byte("18446744073709551614"))
|
||||
maybePanic(err)
|
||||
assertUint64(t, i, "UnmarshalText() uint64")
|
||||
|
||||
var blank Uint64
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullUint64(t, blank, "UnmarshalText() empty uint64")
|
||||
}
|
||||
|
||||
func TestMarshalUint64(t *testing.T) {
|
||||
i := Uint64From(18446744073709551614)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "18446744073709551614", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint64(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalUint64Text(t *testing.T) {
|
||||
i := Uint64From(18446744073709551614)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "18446744073709551614", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint64(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestUint64Pointer(t *testing.T) {
|
||||
i := Uint64From(18446744073709551614)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 18446744073709551614 {
|
||||
t.Errorf("bad %s uint64: %#v ≠ %d\n", "pointer", ptr, uint64(18446744073709551614))
|
||||
}
|
||||
|
||||
null := NewUint64(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s uint64: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint64IsNull(t *testing.T) {
|
||||
i := Uint64From(18446744073709551614)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewUint64(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewUint64(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint64SetValid(t *testing.T) {
|
||||
change := NewUint64(0, false)
|
||||
assertNullUint64(t, change, "SetValid()")
|
||||
change.SetValid(18446744073709551614)
|
||||
assertUint64(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestUint64Scan(t *testing.T) {
|
||||
var i Uint64
|
||||
err := i.Scan(uint64(18446744073709551614))
|
||||
maybePanic(err)
|
||||
assertUint64(t, i, "scanned uint64")
|
||||
|
||||
var null Uint64
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullUint64(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertUint64(t *testing.T, i Uint64, from string) {
|
||||
if i.Uint64 != 18446744073709551614 {
|
||||
t.Errorf("bad %s uint64: %d ≠ %d\n", from, i.Uint64, uint64(18446744073709551614))
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullUint64(t *testing.T, i Uint64, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/nullbio/null.v6/convert"
|
||||
)
|
||||
|
||||
// Uint8 is an nullable uint8.
|
||||
type Uint8 struct {
|
||||
Uint8 uint8
|
||||
Valid bool
|
||||
}
|
||||
|
||||
// NewUint8 creates a new Uint8
|
||||
func NewUint8(i uint8, valid bool) Uint8 {
|
||||
return Uint8{
|
||||
Uint8: i,
|
||||
Valid: valid,
|
||||
}
|
||||
}
|
||||
|
||||
// Uint8From creates a new Uint8 that will always be valid.
|
||||
func Uint8From(i uint8) Uint8 {
|
||||
return NewUint8(i, true)
|
||||
}
|
||||
|
||||
// Uint8FromPtr creates a new Uint8 that be null if i is nil.
|
||||
func Uint8FromPtr(i *uint8) Uint8 {
|
||||
if i == nil {
|
||||
return NewUint8(0, false)
|
||||
}
|
||||
return NewUint8(*i, true)
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements json.Unmarshaler.
|
||||
func (u *Uint8) UnmarshalJSON(data []byte) error {
|
||||
if bytes.Equal(data, NullBytes) {
|
||||
u.Valid = false
|
||||
u.Uint8 = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
var x uint64
|
||||
if err := json.Unmarshal(data, &x); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if x > math.MaxUint8 {
|
||||
return fmt.Errorf("json: %d overflows max uint8 value", x)
|
||||
}
|
||||
|
||||
u.Uint8 = uint8(x)
|
||||
u.Valid = true
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements encoding.TextUnmarshaler.
|
||||
func (u *Uint8) UnmarshalText(text []byte) error {
|
||||
if text == nil || len(text) == 0 {
|
||||
u.Valid = false
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
res, err := strconv.ParseUint(string(text), 10, 8)
|
||||
u.Valid = err == nil
|
||||
if u.Valid {
|
||||
u.Uint8 = uint8(res)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// MarshalJSON implements json.Marshaler.
|
||||
func (u Uint8) MarshalJSON() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return NullBytes, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint8), 10)), nil
|
||||
}
|
||||
|
||||
// MarshalText implements encoding.TextMarshaler.
|
||||
func (u Uint8) MarshalText() ([]byte, error) {
|
||||
if !u.Valid {
|
||||
return []byte{}, nil
|
||||
}
|
||||
return []byte(strconv.FormatUint(uint64(u.Uint8), 10)), nil
|
||||
}
|
||||
|
||||
// SetValid changes this Uint8's value and also sets it to be non-null.
|
||||
func (u *Uint8) SetValid(n uint8) {
|
||||
u.Uint8 = n
|
||||
u.Valid = true
|
||||
}
|
||||
|
||||
// Ptr returns a pointer to this Uint8's value, or a nil pointer if this Uint8 is null.
|
||||
func (u Uint8) Ptr() *uint8 {
|
||||
if !u.Valid {
|
||||
return nil
|
||||
}
|
||||
return &u.Uint8
|
||||
}
|
||||
|
||||
// IsNull returns true for invalid Uint8's, for future omitempty support (Go 1.4?)
|
||||
func (u Uint8) IsNull() bool {
|
||||
return !u.Valid
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (u *Uint8) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
u.Uint8, u.Valid = 0, false
|
||||
return nil
|
||||
}
|
||||
u.Valid = true
|
||||
return convert.ConvertAssign(&u.Uint8, value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (u Uint8) Value() (driver.Value, error) {
|
||||
if !u.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return int64(u.Uint8), nil
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
uint8JSON = []byte(`254`)
|
||||
)
|
||||
|
||||
func TestUint8From(t *testing.T) {
|
||||
i := Uint8From(254)
|
||||
assertUint8(t, i, "Uint8From()")
|
||||
|
||||
zero := Uint8From(0)
|
||||
if !zero.Valid {
|
||||
t.Error("Uint8From(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint8FromPtr(t *testing.T) {
|
||||
n := uint8(254)
|
||||
iptr := &n
|
||||
i := Uint8FromPtr(iptr)
|
||||
assertUint8(t, i, "Uint8FromPtr()")
|
||||
|
||||
null := Uint8FromPtr(nil)
|
||||
assertNullUint8(t, null, "Uint8FromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalUint8(t *testing.T) {
|
||||
var i Uint8
|
||||
err := json.Unmarshal(uint8JSON, &i)
|
||||
maybePanic(err)
|
||||
assertUint8(t, i, "uint8 json")
|
||||
|
||||
var null Uint8
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullUint8(t, null, "null json")
|
||||
|
||||
var badType Uint8
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullUint8(t, badType, "wrong type json")
|
||||
|
||||
var invalid Uint8
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullUint8(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonUintegerNumber8(t *testing.T) {
|
||||
var i Uint8
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-integer number coerced to uint8")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnmarshalUint8Overflow(t *testing.T) {
|
||||
uint8Overflow := int64(math.MaxUint8)
|
||||
|
||||
// Max uint8 should decode successfully
|
||||
var i Uint8
|
||||
err := json.Unmarshal([]byte(strconv.FormatUint(uint64(uint8Overflow), 10)), &i)
|
||||
maybePanic(err)
|
||||
|
||||
// Attempt to overflow
|
||||
uint8Overflow++
|
||||
err = json.Unmarshal([]byte(strconv.FormatUint(uint64(uint8Overflow), 10)), &i)
|
||||
if err == nil {
|
||||
panic("err should be present; decoded value overflows uint8")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalUint8(t *testing.T) {
|
||||
var i Uint8
|
||||
err := i.UnmarshalText([]byte("254"))
|
||||
maybePanic(err)
|
||||
assertUint8(t, i, "UnmarshalText() uint8")
|
||||
|
||||
var blank Uint8
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullUint8(t, blank, "UnmarshalText() empty uint8")
|
||||
}
|
||||
|
||||
func TestMarshalUint8(t *testing.T) {
|
||||
i := Uint8From(254)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "254", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint8(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalUint8Text(t *testing.T) {
|
||||
i := Uint8From(254)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "254", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint8(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestUint8Pointer(t *testing.T) {
|
||||
i := Uint8From(254)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 254 {
|
||||
t.Errorf("bad %s uint8: %#v ≠ %d\n", "pointer", ptr, 254)
|
||||
}
|
||||
|
||||
null := NewUint8(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s uint8: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint8IsNull(t *testing.T) {
|
||||
i := Uint8From(254)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewUint8(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewUint8(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUint8SetValid(t *testing.T) {
|
||||
change := NewUint8(0, false)
|
||||
assertNullUint8(t, change, "SetValid()")
|
||||
change.SetValid(254)
|
||||
assertUint8(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestUint8Scan(t *testing.T) {
|
||||
var i Uint8
|
||||
err := i.Scan(254)
|
||||
maybePanic(err)
|
||||
assertUint8(t, i, "scanned uint8")
|
||||
|
||||
var null Uint8
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullUint8(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertUint8(t *testing.T, i Uint8, from string) {
|
||||
if i.Uint8 != 254 {
|
||||
t.Errorf("bad %s uint8: %d ≠ %d\n", from, i.Uint8, 254)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullUint8(t *testing.T, i Uint8, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
package null
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
uintJSON = []byte(`12345`)
|
||||
)
|
||||
|
||||
func TestUintFrom(t *testing.T) {
|
||||
i := UintFrom(12345)
|
||||
assertUint(t, i, "UintFrom()")
|
||||
|
||||
zero := UintFrom(0)
|
||||
if !zero.Valid {
|
||||
t.Error("UintFrom(0)", "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUintFromPtr(t *testing.T) {
|
||||
n := uint(12345)
|
||||
iptr := &n
|
||||
i := UintFromPtr(iptr)
|
||||
assertUint(t, i, "UintFromPtr()")
|
||||
|
||||
null := UintFromPtr(nil)
|
||||
assertNullUint(t, null, "UintFromPtr(nil)")
|
||||
}
|
||||
|
||||
func TestUnmarshalUint(t *testing.T) {
|
||||
var i Uint
|
||||
err := json.Unmarshal(uintJSON, &i)
|
||||
maybePanic(err)
|
||||
assertUint(t, i, "uint json")
|
||||
|
||||
var null Uint
|
||||
err = json.Unmarshal(nullJSON, &null)
|
||||
maybePanic(err)
|
||||
assertNullUint(t, null, "null json")
|
||||
|
||||
var badType Uint
|
||||
err = json.Unmarshal(boolJSON, &badType)
|
||||
if err == nil {
|
||||
panic("err should not be nil")
|
||||
}
|
||||
assertNullUint(t, badType, "wrong type json")
|
||||
|
||||
var invalid Uint
|
||||
err = invalid.UnmarshalJSON(invalidJSON)
|
||||
if _, ok := err.(*json.SyntaxError); !ok {
|
||||
t.Errorf("expected json.SyntaxError, not %T", err)
|
||||
}
|
||||
assertNullUint(t, invalid, "invalid json")
|
||||
}
|
||||
|
||||
func TestUnmarshalNonUintegerNumber(t *testing.T) {
|
||||
var i Uint
|
||||
err := json.Unmarshal(float64JSON, &i)
|
||||
if err == nil {
|
||||
panic("err should be present; non-uinteger number coerced to uint")
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextUnmarshalUint(t *testing.T) {
|
||||
var i Uint
|
||||
err := i.UnmarshalText([]byte("12345"))
|
||||
maybePanic(err)
|
||||
assertUint(t, i, "UnmarshalText() uint")
|
||||
|
||||
var blank Uint
|
||||
err = blank.UnmarshalText([]byte(""))
|
||||
maybePanic(err)
|
||||
assertNullUint(t, blank, "UnmarshalText() empty uint")
|
||||
}
|
||||
|
||||
func TestMarshalUint(t *testing.T) {
|
||||
i := UintFrom(12345)
|
||||
data, err := json.Marshal(i)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "12345", "non-empty json marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint(0, false)
|
||||
data, err = json.Marshal(null)
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "null", "null json marshal")
|
||||
}
|
||||
|
||||
func TestMarshalUintText(t *testing.T) {
|
||||
i := UintFrom(12345)
|
||||
data, err := i.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "12345", "non-empty text marshal")
|
||||
|
||||
// invalid values should be encoded as null
|
||||
null := NewUint(0, false)
|
||||
data, err = null.MarshalText()
|
||||
maybePanic(err)
|
||||
assertJSONEquals(t, data, "", "null text marshal")
|
||||
}
|
||||
|
||||
func TestUintPointer(t *testing.T) {
|
||||
i := UintFrom(12345)
|
||||
ptr := i.Ptr()
|
||||
if *ptr != 12345 {
|
||||
t.Errorf("bad %s uint: %#v ≠ %d\n", "pointer", ptr, 12345)
|
||||
}
|
||||
|
||||
null := NewUint(0, false)
|
||||
ptr = null.Ptr()
|
||||
if ptr != nil {
|
||||
t.Errorf("bad %s uint: %#v ≠ %s\n", "nil pointer", ptr, "nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUintIsNull(t *testing.T) {
|
||||
i := UintFrom(12345)
|
||||
if i.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
null := NewUint(0, false)
|
||||
if !null.IsNull() {
|
||||
t.Errorf("IsNull() should be true")
|
||||
}
|
||||
|
||||
zero := NewUint(0, true)
|
||||
if zero.IsNull() {
|
||||
t.Errorf("IsNull() should be false")
|
||||
}
|
||||
|
||||
var testInt interface{}
|
||||
testInt = zero
|
||||
if _, ok := testInt.(Nullable); !ok {
|
||||
t.Errorf("Nullable interface should be implemented")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUintSetValid(t *testing.T) {
|
||||
change := NewUint(0, false)
|
||||
assertNullUint(t, change, "SetValid()")
|
||||
change.SetValid(12345)
|
||||
assertUint(t, change, "SetValid()")
|
||||
}
|
||||
|
||||
func TestUintScan(t *testing.T) {
|
||||
var i Uint
|
||||
err := i.Scan(12345)
|
||||
maybePanic(err)
|
||||
assertUint(t, i, "scanned uint")
|
||||
|
||||
var null Uint
|
||||
err = null.Scan(nil)
|
||||
maybePanic(err)
|
||||
assertNullUint(t, null, "scanned null")
|
||||
}
|
||||
|
||||
func assertUint(t *testing.T, i Uint, from string) {
|
||||
if i.Uint != 12345 {
|
||||
t.Errorf("bad %s uint: %d ≠ %d\n", from, i.Uint, 12345)
|
||||
}
|
||||
if !i.Valid {
|
||||
t.Error(from, "is invalid, but should be valid")
|
||||
}
|
||||
}
|
||||
|
||||
func assertNullUint(t *testing.T, i Uint, from string) {
|
||||
if i.Valid {
|
||||
t.Error(from, "is valid, but should be invalid")
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
"github.com/lbryio/lbry.go/extras/null"
|
||||
)
|
||||
|
||||
func InterpolateParams(query string, args ...interface{}) (string, error) {
|
||||
for i := 0; i < len(args); i++ {
|
||||
field := reflect.ValueOf(args[i])
|
||||
|
||||
if value, ok := field.Interface().(time.Time); ok {
|
||||
query = strings.Replace(query, "?", `"`+value.Format("2006-01-02 15:04:05")+`"`, 1)
|
||||
} else if nullable, ok := field.Interface().(null.Nullable); ok {
|
||||
if nullable.IsNull() {
|
||||
query = strings.Replace(query, "?", "NULL", 1)
|
||||
} else {
|
||||
switch field.Type() {
|
||||
case reflect.TypeOf(null.Time{}):
|
||||
query = strings.Replace(query, "?", `"`+field.Interface().(null.Time).Time.Format("2006-01-02 15:04:05")+`"`, 1)
|
||||
case reflect.TypeOf(null.Int{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(int64(field.Interface().(null.Int).Int), 10), 1)
|
||||
case reflect.TypeOf(null.Int8{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(int64(field.Interface().(null.Int8).Int8), 10), 1)
|
||||
case reflect.TypeOf(null.Int16{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(int64(field.Interface().(null.Int16).Int16), 10), 1)
|
||||
case reflect.TypeOf(null.Int32{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(int64(field.Interface().(null.Int32).Int32), 10), 1)
|
||||
case reflect.TypeOf(null.Int64{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(field.Interface().(null.Int64).Int64, 10), 1)
|
||||
case reflect.TypeOf(null.Uint{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(uint64(field.Interface().(null.Uint).Uint), 10), 1)
|
||||
case reflect.TypeOf(null.Uint8{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(uint64(field.Interface().(null.Uint8).Uint8), 10), 1)
|
||||
case reflect.TypeOf(null.Uint16{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(uint64(field.Interface().(null.Uint16).Uint16), 10), 1)
|
||||
case reflect.TypeOf(null.Uint32{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(uint64(field.Interface().(null.Uint32).Uint32), 10), 1)
|
||||
case reflect.TypeOf(null.Uint64{}):
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(field.Interface().(null.Uint64).Uint64, 10), 1)
|
||||
case reflect.TypeOf(null.String{}):
|
||||
query = strings.Replace(query, "?", `"`+field.Interface().(null.String).String+`"`, 1)
|
||||
case reflect.TypeOf(null.Bool{}):
|
||||
if field.Interface().(null.Bool).Bool {
|
||||
query = strings.Replace(query, "?", "1", 1)
|
||||
} else {
|
||||
query = strings.Replace(query, "?", "0", 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch field.Kind() {
|
||||
case reflect.Bool:
|
||||
boolString := "0"
|
||||
if field.Bool() {
|
||||
boolString = "1"
|
||||
}
|
||||
query = strings.Replace(query, "?", boolString, 1)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
query = strings.Replace(query, "?", strconv.FormatInt(field.Int(), 10), 1)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
query = strings.Replace(query, "?", strconv.FormatUint(field.Uint(), 10), 1)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
query = strings.Replace(query, "?", strconv.FormatFloat(field.Float(), 'f', -1, 64), 1)
|
||||
case reflect.String:
|
||||
query = strings.Replace(query, "?", `"`+field.String()+`"`, 1)
|
||||
case reflect.Slice:
|
||||
query = strings.Replace(query, "?", `x`+fmt.Sprintf("%0x", field), 1)
|
||||
default:
|
||||
return "", errors.Err("dont know how to interpolate type " + field.Type().String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tabs to spaces, for easier copying into mysql prompt
|
||||
query = strings.Replace(query, "\t", " ", -1)
|
||||
|
||||
return query, nil
|
||||
}
|
||||
|
||||
// Qs is a shortcut for one group of positional placeholders
|
||||
func Qs(count int) string {
|
||||
return placeholders(false, count, 1, 1)
|
||||
}
|
||||
|
||||
// placeholders creates indexed or positional placeholders, in groups, with different starts
|
||||
func placeholders(indexPlaceholders bool, count int, start int, group int) string {
|
||||
buf := bytes.Buffer{}
|
||||
|
||||
if start == 0 || group == 0 {
|
||||
panic("invalid start or group numbers supplied.")
|
||||
}
|
||||
|
||||
if group > 1 {
|
||||
buf.WriteByte('(')
|
||||
}
|
||||
for i := 0; i < count; i++ {
|
||||
if i != 0 {
|
||||
if group > 1 && i%group == 0 {
|
||||
buf.WriteString("),(")
|
||||
} else {
|
||||
buf.WriteByte(',')
|
||||
}
|
||||
}
|
||||
if indexPlaceholders {
|
||||
buf.WriteString(fmt.Sprintf("$%d", start+i))
|
||||
} else {
|
||||
buf.WriteByte('?')
|
||||
}
|
||||
}
|
||||
if group > 1 {
|
||||
buf.WriteByte(')')
|
||||
}
|
||||
|
||||
return buf.String()
|
||||
}
|
||||
+9
-4
@@ -23,7 +23,7 @@ import (
|
||||
// Chan is a receive-only channel
|
||||
type Chan <-chan struct{}
|
||||
|
||||
// Stopper extends sync.WaitGroup to add a convenient way to stop running goroutines
|
||||
// Group extends sync.WaitGroup to add a convenient way to stop running goroutines
|
||||
type Group struct {
|
||||
sync.WaitGroup
|
||||
ctx context.Context
|
||||
@@ -101,8 +101,6 @@ func (s *Group) DoneNamed(name string) {
|
||||
|
||||
if s.waitingOn != nil {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if current, ok := s.waitingOn[name]; ok {
|
||||
if current <= 1 {
|
||||
delete(s.waitingOn, name)
|
||||
@@ -112,9 +110,16 @@ func (s *Group) DoneNamed(name string) {
|
||||
} else {
|
||||
log.Printf("%s is not recorded in stop group map", name)
|
||||
}
|
||||
s.mu.Unlock()
|
||||
s.listWaitingOn()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Group) listWaitingOn() {
|
||||
if s.waitingOn != nil {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
log.Printf("-->> LIST ROUTINES WAITING ON")
|
||||
|
||||
for k, v := range s.waitingOn {
|
||||
if v > 0 {
|
||||
log.Printf("waiting on %d %s routines...", v, k)
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
package travis
|
||||
|
||||
/*
|
||||
Copyright 2017 Shapath Neupane (@theshapguy)
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
------------------------------------------------
|
||||
Listener - written in Go because it's native web server is much more robust than Python. Plus its fun to write Go!
|
||||
NOTE: Make sure you are using the right domain for travis [.com] or [.org]
|
||||
Modified by wilsonk@lbry.io for LBRY internal-apis
|
||||
*/
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
"crypto/rsa"
|
||||
"crypto/sha1"
|
||||
"crypto/x509"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"encoding/pem"
|
||||
"net/http"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
)
|
||||
|
||||
func publicKey(isPrivateRepo bool) (*rsa.PublicKey, error) {
|
||||
var response *http.Response
|
||||
var err error
|
||||
if !isPrivateRepo {
|
||||
response, err = http.Get("https://api.travis-ci.org/config")
|
||||
} else {
|
||||
response, err = http.Get("https://api.travis-ci.com/config")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Err("cannot fetch travis public key")
|
||||
}
|
||||
defer response.Body.Close()
|
||||
|
||||
type configKey struct {
|
||||
Config struct {
|
||||
Notifications struct {
|
||||
Webhook struct {
|
||||
PublicKey string `json:"public_key"`
|
||||
} `json:"webhook"`
|
||||
} `json:"notifications"`
|
||||
} `json:"config"`
|
||||
}
|
||||
|
||||
var t configKey
|
||||
|
||||
decoder := json.NewDecoder(response.Body)
|
||||
err = decoder.Decode(&t)
|
||||
if err != nil {
|
||||
return nil, errors.Err("cannot decode travis public key")
|
||||
}
|
||||
|
||||
keyBlock, _ := pem.Decode([]byte(t.Config.Notifications.Webhook.PublicKey))
|
||||
if keyBlock == nil || keyBlock.Type != "PUBLIC KEY" {
|
||||
return nil, errors.Err("invalid travis public key")
|
||||
}
|
||||
|
||||
publicKey, err := x509.ParsePKIXPublicKey(keyBlock.Bytes)
|
||||
if err != nil {
|
||||
return nil, errors.Err("invalid travis public key")
|
||||
}
|
||||
|
||||
return publicKey.(*rsa.PublicKey), nil
|
||||
}
|
||||
|
||||
func payloadDigest(payload string) []byte {
|
||||
hash := sha1.New()
|
||||
hash.Write([]byte(payload))
|
||||
return hash.Sum(nil)
|
||||
}
|
||||
|
||||
func ValidateSignature(isPrivateRepo bool, r *http.Request) error {
|
||||
key, err := publicKey(isPrivateRepo)
|
||||
if err != nil {
|
||||
return errors.Err(err)
|
||||
}
|
||||
|
||||
signature, err := base64.StdEncoding.DecodeString(r.Header.Get("Signature"))
|
||||
if err != nil {
|
||||
return errors.Err("cannot decode signature")
|
||||
}
|
||||
|
||||
payload := payloadDigest(r.FormValue("payload"))
|
||||
|
||||
err = rsa.VerifyPKCS1v15(key, crypto.SHA1, payload, signature)
|
||||
if err != nil {
|
||||
if err == rsa.ErrVerification {
|
||||
return errors.Err("invalid payload signature")
|
||||
}
|
||||
return errors.Err(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewFromRequest(r *http.Request) (*Webhook, error) {
|
||||
w := new(Webhook)
|
||||
|
||||
err := json.Unmarshal([]byte(r.FormValue("payload")), w)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
}
|
||||
|
||||
return w, nil
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package travis
|
||||
|
||||
import "time"
|
||||
|
||||
// https://docs.travis-ci.com/user/notifications/#Webhooks-Delivery-Format
|
||||
|
||||
const (
|
||||
statusSuccess = 0
|
||||
statusNotSuccess = 1
|
||||
)
|
||||
|
||||
type Webhook struct {
|
||||
ID int `json:"id"`
|
||||
Number string `json:"number"`
|
||||
Type string `json:"type"`
|
||||
State string `json:"state"`
|
||||
Status int `json:"status"` // status and result are the same
|
||||
Result int `json:"result"`
|
||||
StatusMessage string `json:"status_message"` // status_message and result_message are the same
|
||||
ResultMessage string `json:"result_message"`
|
||||
StartedAt time.Time `json:"started_at"`
|
||||
FinishedAt time.Time `json:"finished_at"`
|
||||
Duration int `json:"duration"`
|
||||
BuildURL string `json:"build_url"`
|
||||
CommitID int `json:"commit_id"`
|
||||
Commit string `json:"commit"`
|
||||
BaseCommit string `json:"base_commit"`
|
||||
HeadCommit string `json:"head_commit"`
|
||||
Branch string `json:"branch"`
|
||||
Message string `json:"message"`
|
||||
CompareURL string `json:"compare_url"`
|
||||
CommittedAt time.Time `json:"committed_at"`
|
||||
AuthorName string `json:"author_name"`
|
||||
AuthorEmail string `json:"author_email"`
|
||||
CommitterName string `json:"committer_name"`
|
||||
CommitterEmail string `json:"committer_email"`
|
||||
PullRequest bool `json:"pull_request"`
|
||||
PullRequestNumber int `json:"pull_request_number"`
|
||||
PullRequestTitle string `json:"pull_request_title"`
|
||||
Tag string `json:"tag"`
|
||||
Repository Repository `json:"repository"`
|
||||
}
|
||||
|
||||
type Repository struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
OwnerName string `json:"owner_name"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// IsMatch make sure the webhook is for you...
|
||||
func (w Webhook) IsMatch(branch string, repo string, owner string) bool {
|
||||
return w.Branch == branch &&
|
||||
w.Repository.Name == repo &&
|
||||
w.Repository.OwnerName == owner
|
||||
}
|
||||
|
||||
func (w Webhook) ShouldDeploy() bool {
|
||||
// when travis builds a pull request, Branch is the target branch, not the origin branch
|
||||
// source: https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
|
||||
return w.Status == statusSuccess && w.Branch == "master" && !w.PullRequest
|
||||
}
|
||||
|
||||
func (w Webhook) DeploySummary() string {
|
||||
return w.Commit[:8] + ": " + w.Message
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"github.com/nlopes/slack"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var defaultChannel string
|
||||
var defaultUsername string
|
||||
var slackApi *slack.Client
|
||||
|
||||
// InitSlack Initializes a slack client with the given token and sets the default channel.
|
||||
func InitSlack(token string, channel string, username string) {
|
||||
slackApi = slack.New(token)
|
||||
defaultChannel = channel
|
||||
defaultUsername = username
|
||||
}
|
||||
|
||||
// SendToSlackUser Sends message to a specific user.
|
||||
func SendToSlackUser(user, username, format string, a ...interface{}) error {
|
||||
message := format
|
||||
if len(a) > 0 {
|
||||
message = fmt.Sprintf(format, a...)
|
||||
}
|
||||
if !strings.HasPrefix(user, "@") {
|
||||
user = "@" + user
|
||||
}
|
||||
return sendToSlack(user, username, message)
|
||||
}
|
||||
|
||||
// SendToSlackChannel Sends message to a specific channel.
|
||||
func SendToSlackChannel(channel, username, format string, a ...interface{}) error {
|
||||
message := format
|
||||
if len(a) > 0 {
|
||||
message = fmt.Sprintf(format, a...)
|
||||
}
|
||||
if !strings.HasPrefix(channel, "#") {
|
||||
channel = "#" + channel
|
||||
}
|
||||
return sendToSlack(channel, username, message)
|
||||
}
|
||||
|
||||
// SendToSlack Sends message to the default channel.
|
||||
func SendToSlack(format string, a ...interface{}) error {
|
||||
message := format
|
||||
if len(a) > 0 {
|
||||
message = fmt.Sprintf(format, a...)
|
||||
}
|
||||
if defaultChannel == "" {
|
||||
return errors.Err("no default slack channel set")
|
||||
}
|
||||
|
||||
return sendToSlack(defaultChannel, defaultUsername, message)
|
||||
}
|
||||
|
||||
func sendToSlack(channel, username, message string) error {
|
||||
var err error
|
||||
|
||||
if slackApi == nil {
|
||||
err = errors.Err("no slack token provided")
|
||||
} else {
|
||||
log.Debugln("slack: " + channel + ": " + message)
|
||||
_, _, err = slackApi.PostMessage(channel, slack.MsgOptionText(message, false), slack.MsgOptionUsername(username))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Errorln("error sending to slack: " + err.Error())
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package util
|
||||
|
||||
import "strings"
|
||||
|
||||
func InSlice(str string, values []string) bool {
|
||||
for _, v := range values {
|
||||
if str == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SubstringInSlice returns true if str is contained within any element of the values slice. False otherwise
|
||||
func SubstringInSlice(str string, values []string) bool {
|
||||
for _, v := range values {
|
||||
if strings.Contains(str, v) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package util
|
||||
|
||||
// https://github.com/go-pg/pg/blob/7c2d9d39a5cfc18a422c88a9f5f39d8d2cd10030/internal/underscore.go
|
||||
|
||||
func isUpper(c byte) bool {
|
||||
return c >= 'A' && c <= 'Z'
|
||||
}
|
||||
|
||||
func isLower(c byte) bool {
|
||||
return !isUpper(c)
|
||||
}
|
||||
|
||||
func toLower(c byte) byte {
|
||||
return c + 32
|
||||
}
|
||||
|
||||
// Underscore converts "CamelCasedString" to "camel_cased_string".
|
||||
func Underscore(s string) string {
|
||||
r := make([]byte, 0, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
c := s[i]
|
||||
if isUpper(c) {
|
||||
if i > 0 && i+1 < len(s) && (isLower(s[i-1]) || isLower(s[i+1])) {
|
||||
r = append(r, '_', toLower(c))
|
||||
} else {
|
||||
r = append(r, toLower(c))
|
||||
}
|
||||
} else {
|
||||
r = append(r, c)
|
||||
}
|
||||
}
|
||||
return string(r)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package validator
|
||||
|
||||
var (
|
||||
truthyValues = []string{"1", "yes", "y", "true"}
|
||||
falseyValues = []string{"0", "no", "n", "false"}
|
||||
)
|
||||
|
||||
// todo: consider using strconv.ParseBool instead
|
||||
|
||||
func IsTruthy(value string) bool {
|
||||
for _, e := range truthyValues {
|
||||
if e == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsFalsey(value string) bool {
|
||||
for _, e := range falseyValues {
|
||||
if e == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsBoolString(value string) bool {
|
||||
return IsTruthy(value) || IsFalsey(value)
|
||||
}
|
||||
|
||||
func GetBoolStringValues() []string {
|
||||
return append(truthyValues, falseyValues...)
|
||||
}
|
||||
@@ -1,51 +1,27 @@
|
||||
module github.com/lbryio/lbry.go
|
||||
module github.com/lbryio/lbry.go/v3
|
||||
|
||||
require (
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf // indirect
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd // indirect
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 // indirect
|
||||
github.com/davecgh/go-spew v1.1.0
|
||||
github.com/go-errors/errors v1.0.1
|
||||
github.com/go-ini/ini v1.38.2
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible // indirect
|
||||
github.com/golang/protobuf v1.3.0
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
|
||||
github.com/gorilla/context v1.1.1 // indirect
|
||||
github.com/gorilla/mux v1.6.2
|
||||
github.com/gorilla/rpc v1.1.0
|
||||
github.com/gorilla/websocket v1.2.0 // indirect
|
||||
github.com/jtolds/gls v4.2.1+incompatible // indirect
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 // indirect
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 // indirect
|
||||
github.com/cockroachdb/errors v1.8.6
|
||||
github.com/davecgh/go-spew v1.1.1
|
||||
github.com/go-errors/errors v1.1.1 // indirect
|
||||
github.com/go-ini/ini v1.48.0
|
||||
github.com/golang/protobuf v1.5.2
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gorilla/rpc v1.2.0
|
||||
github.com/lbryio/lbcd v0.22.200-beta
|
||||
github.com/lbryio/lbcutil v1.0.202-rc3
|
||||
github.com/lbryio/lbry.go/v2 v2.7.1
|
||||
github.com/lbryio/types v0.0.0-20201019032447-f0b4476ef386
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675
|
||||
github.com/nlopes/slack v0.5.0
|
||||
github.com/onsi/gomega v1.4.3 // indirect
|
||||
github.com/pkg/errors v0.8.1 // indirect
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561
|
||||
github.com/sergi/go-diff v1.0.0
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c // indirect
|
||||
github.com/spf13/cast v1.2.0
|
||||
github.com/stretchr/testify v1.3.0 // indirect
|
||||
github.com/uber-go/atomic v1.3.2
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d
|
||||
go.uber.org/atomic v1.3.2 // indirect
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f // indirect
|
||||
google.golang.org/grpc v1.17.0
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
|
||||
gopkg.in/ini.v1 v1.41.0 // indirect
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77
|
||||
github.com/sergi/go-diff v1.1.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cast v1.3.0
|
||||
github.com/stretchr/testify v1.7.0
|
||||
go.uber.org/atomic v1.7.0
|
||||
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
go 1.16
|
||||
@@ -1,136 +1,855 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a h1:fuEu3WaOzatbWFGlCa2e/TL/GR397Da8QSKNKrDRa3s=
|
||||
github.com/btcsuite/btcd v0.0.0-20180531025944-86fed781132a/go.mod h1:Dmm/EzmjnCiweXmzRIAiUWCInVmPgjkzgv5k4tVyXiQ=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
||||
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOvUY6CB00SOBii9/FifXqc0awNKxLFCL/+pkDPuyl8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/CloudyKit/fastprinter v0.0.0-20170127035650-74b38d55f37a/go.mod h1:EFZQ978U7x8IRnstaskI3IysnWY5Ao3QgZUKOXlsAdw=
|
||||
github.com/CloudyKit/jet v2.1.3-0.20180809161101-62edd43e4f88+incompatible/go.mod h1:HPYO+50pSWkPoj9Q/eq0aRGByCL6ScRlUmiEX5Zgm+w=
|
||||
github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
|
||||
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
|
||||
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
|
||||
github.com/Joker/jade v1.0.1-0.20190614124447-d475f43051e7/go.mod h1:6E6s8o2AE4KhCrqr6GRJjdC/gNfTdxkIXvuGZZda2VM=
|
||||
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
|
||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
|
||||
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
|
||||
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/btcsuite/btcd v0.0.0-20190213025234-306aecffea32/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btcd v0.22.0-beta/go.mod h1:9n5ntfhhHQBIhUvlhDvD3Qg6fRUj4jkN0VB8L8svzOA=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016 h1:BsZAJgCuMsoFZMZNyj7Lyt6sS8anDhedVrAMCOyPMIo=
|
||||
github.com/btcsuite/btcutil v0.0.0-20180524032703-d4cc87b86016/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
|
||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
|
||||
github.com/cockroachdb/datadriven v1.0.0/go.mod h1:5Ib8Meh+jk1RlHIXej6Pzevx/NLlNvQB9pmSBZErGA4=
|
||||
github.com/cockroachdb/errors v1.6.1/go.mod h1:tm6FTP5G81vwJ5lC0SizQo374JNCOPrHyXGitRJoDqM=
|
||||
github.com/cockroachdb/errors v1.8.1/go.mod h1:qGwQn6JmZ+oMjuLwjWzUNqblqk0xl4CVV3SQbGwK7Ac=
|
||||
github.com/cockroachdb/errors v1.8.6 h1:Am9evxl/po3RzpokemQvq7S7Cd0mxv24xy0B/trlQF4=
|
||||
github.com/cockroachdb/errors v1.8.6/go.mod h1:hOm5fabihW+xEyY1kuypGwqT+Vt7rafg04ytBtIpeIQ=
|
||||
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
|
||||
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f h1:6jduT9Hfc0njg5jJ1DdKCFPdMBrp/mdZfCpa5h+WM74=
|
||||
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f/go.mod h1:Vz9DsVWQQhf3vs21MhPMZpMGSht7O/2vFW2xusFUVOs=
|
||||
github.com/cockroachdb/pebble v0.0.0-20210525181856-e45797baeb78/go.mod h1:1XpB4cLQcF189RAcWi4gUc110zJgtOfT7SVNGY8sOe0=
|
||||
github.com/cockroachdb/pebble v0.0.0-20211124004043-0dc90bc41e62/go.mod h1:buxOO9GBtOcq1DiXDpIPYrmxY020K2A8lOrwno5FetU=
|
||||
github.com/cockroachdb/redact v1.0.8/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||
github.com/cockroachdb/redact v1.1.1/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||
github.com/cockroachdb/redact v1.1.3 h1:AKZds10rFSIj7qADf0g46UixK8NNLwWTNdCIGS5wfSQ=
|
||||
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
|
||||
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2 h1:IKgmqgMQlVJIZj19CdocBeSfSaiCbEBZGKODaixqtHM=
|
||||
github.com/cockroachdb/sentry-go v0.6.1-cockroachdb.2/go.mod h1:8BT+cPK6xvFOcRlk0R8eg+OTkcqI6baNH4xAkpiYVvQ=
|
||||
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
|
||||
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
|
||||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
|
||||
github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM=
|
||||
github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHjkjCrw=
|
||||
github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/felixge/fgprof v0.9.1/go.mod h1:7/HK6JFtFaARhIljgP2IV8rJLIoHDoOYoUphsnGvqxE=
|
||||
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nIgbVgp3rreNmTged+9HrbNTIQf1PsaIiTA=
|
||||
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
|
||||
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
|
||||
github.com/ghemawat/stream v0.0.0-20171120220530-696b145b53b9/go.mod h1:106OIgooyS7OzLDOpUGgm9fA3bQENb/cFSyyBmMoJDs=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s=
|
||||
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
|
||||
github.com/go-check/check v0.0.0-20180628173108-788fd7840127/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-ini/ini v1.38.2 h1:6Hl/z3p3iFkA0dlDfzYxuFuUGD+kaweypF6btsR2/Q4=
|
||||
github.com/go-ini/ini v1.38.2/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible h1:sUy/in/P6askYr16XJgTKq/0SZhiWsdg4WZGaLsGQkM=
|
||||
github.com/go-ozzo/ozzo-validation v3.5.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/go-errors/errors v1.1.1 h1:ljK/pL5ltg3qoN+OtN6yCv9HWSfMwxSx90GJCZQxYNg=
|
||||
github.com/go-errors/errors v1.1.1/go.mod h1:psDX2osz5VnTOnFWbDeWwS7yejl+uV3FEWEp4lssFEs=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
||||
github.com/go-ini/ini v1.48.0 h1:TvO60hO/2xgaaTWp2P0wUe4CFxwdMzfbkv3+343Xzqw=
|
||||
github.com/go-ini/ini v1.48.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
|
||||
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ozzo/ozzo-validation v3.6.0+incompatible/go.mod h1:gsEKFIVnabGBt6mXmxK0MoFy+cZoTJY6mu5Ll3LVLBU=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
|
||||
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
|
||||
github.com/gogo/googleapis v0.0.0-20180223154316-0cd9801be74a/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||
github.com/gogo/googleapis v1.4.1/go.mod h1:2lpHqI5OcWCtVElxXnPt+s8oJvMpySlOyM6xDCrzib4=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
|
||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
||||
github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY1WM=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
|
||||
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1ks85zJ1lfDGgIiMDuIptTOhJq+zKyg=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.2-0.20190904063534-ff6b7dc882cf/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gomodule/redigo v1.7.1-0.20190724094224-574c33c3df38/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20200615235658-03e1cf38a040/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f h1:TyqzGm2z1h3AGhjOoRYyeLcW4WlW81MDQkWa+rx/000=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20190915194858-d3ddacdb130f/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2 h1:Pgr17XVTNXAk3q/r4CpKzC5xBM/qW1uVLV+IhRZpIIk=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/rpc v1.1.0 h1:marKfvVP0Gpd/jHlVBKCQ8RAoUPdX7K1Nuh6l1BNh7A=
|
||||
github.com/gorilla/rpc v1.1.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
|
||||
github.com/gorilla/websocket v1.2.0 h1:VJtLvh6VQym50czpZzx07z/kw9EgAxI3x1ZB8taTMQQ=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/rpc v1.2.0 h1:WvvdC2lNeT1SP32zrIce5l0ECBfbAlmrmSBsuc57wfk=
|
||||
github.com/gorilla/rpc v1.2.0/go.mod h1:V4h9r+4sF5HnzqbwIez0fKSpANP0zlYd3qR7p36jkTQ=
|
||||
github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
|
||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
|
||||
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
|
||||
github.com/hydrogen18/memlistener v0.0.0-20141126152155-54553eb933fb/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
|
||||
github.com/hydrogen18/memlistener v0.0.0-20200120041712-dcc25e7acd91/go.mod h1:qEIFzExnS6016fRpRfxrExeVn2gbClQA99gQhnIcdhE=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
|
||||
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
|
||||
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
|
||||
github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI=
|
||||
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5/go.mod h1:W54LbzXuIE0boCoNJfwqpmkKJ1O4TCTZMetAt6jGk7Q=
|
||||
github.com/juju/loggo v0.0.0-20180524022052-584905176618/go.mod h1:vgyd7OREkbtVEN/8IXZe5Ooef3LQePvuBm9UWj6ZL8U=
|
||||
github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0tU0S9OHjGJn+b1h0ZghCndfnbQolrYTwA=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
|
||||
github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk=
|
||||
github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U=
|
||||
github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw=
|
||||
github.com/kataras/pio v0.0.0-20190103105442-ea782b38602d/go.mod h1:NV88laa9UiiDuX9AhMbDPkGYSPugBOV6yTZB1l2K9Z0=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c h1:BhdcWGsuKif/XoSZnqVGNqJ1iEmH0czWR5upj+AuR8M=
|
||||
github.com/lbryio/errors.go v0.0.0-20180223142025-ad03d3cc6a5c/go.mod h1:muH7wpUqE8hRA3OrYYosw9+Sl681BF9cwcjzE+OCNK8=
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04 h1:Nze+C2HbeKvhjI/kVn+9Poj/UuEW5sOQxcsxqO7L3GI=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA=
|
||||
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.9.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/labstack/echo/v4 v4.1.11/go.mod h1:i541M3Fj6f76NZtHSj7TXnyM8n2gaodfvfxNnFqi74g=
|
||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||
github.com/lbryio/lbcd v0.22.100-beta/go.mod h1:u8SaFX4xdGMMR5xasBGfgApC8pvD4rnK2OujZnrq5gs=
|
||||
github.com/lbryio/lbcd v0.22.100-beta-rc5/go.mod h1:9PbFSlHYX7WlnDQwcTxHVf1W35VAnRsattCSyKOO55g=
|
||||
github.com/lbryio/lbcd v0.22.200-beta h1:MmBUu33GMC4SLN7q6C1hX8YsBUCLHI8MY0uRuRwA/oU=
|
||||
github.com/lbryio/lbcd v0.22.200-beta/go.mod h1:kNuzGWf808ipTGB0y0WogzsGv5BVM4Qv85Z+JYwC9FA=
|
||||
github.com/lbryio/lbcutil v1.0.201/go.mod h1:gDHc/b+Rdz3J7+VB8e5/Bl9roVf8Q5/8FQCyuK9dXD0=
|
||||
github.com/lbryio/lbcutil v1.0.202-rc3 h1:J7zYnIj3iN/ndPYKqMKBukLaLM1GhCEaiaMOYIMdUCU=
|
||||
github.com/lbryio/lbcutil v1.0.202-rc3/go.mod h1:LGPtVBBzh4cFXfLFb8ginlFcbA2QwumLNFd0yk/as2o=
|
||||
github.com/lbryio/lbry.go/v2 v2.7.1 h1:izea4/5E7qdXUibleJmGw2iSo11p2kd15FALM3F2/Qc=
|
||||
github.com/lbryio/lbry.go/v2 v2.7.1/go.mod h1:sUhhSKqPNkiwgBqvBzJIqfLLzGH8hkDGrrO/HcaXzFc=
|
||||
github.com/lbryio/ozzo-validation v0.0.0-20170323141101-d1008ad1fd04/go.mod h1:fbG/dzobG8r95KzMwckXiLMHfFjZaBRQqC9hPs2XAQ4=
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38 h1:78rErXiBhMjs7vh4Ke3ZMqQjf+pnQeNrkXYmQ8L6aKE=
|
||||
github.com/lbryio/types v0.0.0-20190304154608-a6f2fd6d5f38/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE=
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5 h1:AsEBgzv3DhuYHI/GiQh2HxvTP71HCCE9E/tzGUzGdtU=
|
||||
github.com/lusis/go-slackbot v0.0.0-20180109053408-401027ccfef5/go.mod h1:c2mYKRyMb1BPkO5St0c/ps62L4S0W2NAkaTXj9qEI+0=
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6 h1:iOAVXzZyXtW408TMYejlUPo6BIn92HmOacWtIfNyYns=
|
||||
github.com/lusis/slack-test v0.0.0-20180109053238-3c758769bfa6/go.mod h1:sFlOUpQL1YcjhFVXhg1CG8ZASEs/Mf1oVb6H75JL/zg=
|
||||
github.com/lbryio/types v0.0.0-20201019032447-f0b4476ef386 h1:JOQkGpeCM9FWkEHRx+kRPqySPCXElNW1em1++7tVS4M=
|
||||
github.com/lbryio/types v0.0.0-20201019032447-f0b4476ef386/go.mod h1:CG3wsDv5BiVYQd5i1Jp7wGsaVyjZTJshqXeWMVKsISE=
|
||||
github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM=
|
||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5 h1:mG83tLXWSRdcXMWfkoumVwhcCbf3jHF9QKv/m37BkM0=
|
||||
github.com/lyoshenka/bencode v0.0.0-20180323155644-b7abd7672df5/go.mod h1:H0aPCWffGOaDcjkw1iB7W9DVLp6GXmfcJY/7YZCWPA4=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675 h1:/rdJjIiKG5rRdwG5yxHmSE/7ZREjpyC0kL7GxGT/qJw=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20180511142126-bb74f1db0675/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/nlopes/slack v0.5.0 h1:NbIae8Kd0NpqaEI3iUrsuS0KbcEDhzhc939jLW5fNm0=
|
||||
github.com/nlopes/slack v0.5.0/go.mod h1:jVI4BBK3lSktibKahxBF74txcK2vyvkza1z/+rRnVAM=
|
||||
github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg=
|
||||
github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQGvsUt6O3Pj+LDCQ=
|
||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||
github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k=
|
||||
github.com/nats-io/nats.go v1.8.1/go.mod h1:BrFz9vVn0fU3AcH9Vn4Kd7W0NpJ651tD5omQ3M8LwxM=
|
||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||
github.com/nats-io/nkeys v0.0.2/go.mod h1:dab7URMsZm6Z/jp9Z5UGa87Uutgc2mVpXLC4B7TDb/4=
|
||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/nlopes/slack v0.6.0/go.mod h1:JzQ9m3PMAqcpeCam7UaHSuBuupz7CmpjehYMayT6YOk=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs=
|
||||
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.13.0/go.mod h1:+REjRxOmWfHCjfv9TTWB1jD1Frx4XydAD3zm1lskyM0=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
|
||||
github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis=
|
||||
github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74=
|
||||
github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
|
||||
github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA=
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
|
||||
github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac=
|
||||
github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561 h1:IY+sDBJR/wRtsxq+626xJnt4Tw7/ROA9cDIR8MMhWyg=
|
||||
github.com/sebdah/goldie v0.0.0-20180424091453-8784dd1ab561/go.mod h1:lvjGftC8oe7XPtyrOidaMi0rp5B9+XY/ZRUynGnuaxQ=
|
||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
|
||||
github.com/rs/zerolog v1.21.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
|
||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77 h1:Msb6XRY62jQOueNNlB5LGin1rljK7c49NLniGwJG2bg=
|
||||
github.com/sebdah/goldie v0.0.0-20190531093107-d313ffb52c77/go.mod h1:jXP4hmWywNEwZzhMuv2ccnqTSFpuq8iyQhtQdkkZBH4=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930 h1:pSgp2x9zCkCjb8rxXFNpGE8hDIrt+UXW7jUQ5fbTlzM=
|
||||
github.com/shopspring/decimal v0.0.0-20180607144847-19e3cb6c2930/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973 h1:3AJZYTzw3gm3TNTt30x0CCKD7GOn2sdd50Hn35fQkGY=
|
||||
github.com/sirupsen/logrus v0.0.0-20180523074243-ea8897e79973/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/shirou/gopsutil/v3 v3.21.7/go.mod h1:RGl11Y7XMTQPmHh8F0ayC6haKNBgH4PXMJuTAcMOlz4=
|
||||
github.com/shopspring/decimal v0.0.0-20191009025716-f1972eb1d1f5/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c h1:Ho+uVpkel/udgjbwB5Lktg9BtvJSh2DT0Hi6LPSyI2w=
|
||||
github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s=
|
||||
github.com/spf13/cast v1.2.0 h1:HHl1DSRbEQN2i8tJmtS6ViPyHx35+p51amrdsiTCrkg=
|
||||
github.com/spf13/cast v1.2.0/go.mod h1:r2rcYCSwa1IExKTDiTfzaxqT2FNHs8hODu4LnUfgKEg=
|
||||
github.com/smartystreets/assertions v1.0.1 h1:voD4ITNjPL5jjBfgR/r8fPIIBrliWrWHeiJApdr3r4w=
|
||||
github.com/smartystreets/assertions v1.0.1/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
||||
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
|
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
|
||||
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
|
||||
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/uber-go/atomic v1.3.2 h1:Azu9lPBWRNKzYXSIwRfgRuDuS0YKsK4NFhiQv98gkxo=
|
||||
github.com/uber-go/atomic v1.3.2/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d h1:tQo6hjclyv3RHUgZOl6iWb2Y44A/sN9bf9LAYfuioEg=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
|
||||
github.com/tklauser/go-sysconf v0.3.7/go.mod h1:JZIdXh4RmBvZDBZ41ld2bGxRV3n4daiiqA3skYhAoQ4=
|
||||
github.com/tklauser/numcpus v0.2.3/go.mod h1:vpEPS/JC+oZGGQ/My/vJnNsvMDQL6PwOqt8dsCw5j+E=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
||||
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
|
||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.2/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
|
||||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
|
||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
|
||||
github.com/ybbus/jsonrpc v0.0.0-20180411222309-2a548b7d822d/go.mod h1:XJrh1eMSzdIYFbM08flv0wp5G35eRniyeGut1z+LSiE=
|
||||
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
|
||||
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
|
||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
|
||||
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||
go.opentelemetry.io/otel v0.20.0/go.mod h1:Y3ugLH2oa81t5QO+Lty+zXf8zC9L26ax4Nzoxm/dooo=
|
||||
go.opentelemetry.io/otel/metric v0.20.0/go.mod h1:598I5tYlH1vzBjn+BTuhzTCSb/9debfNp6R3s7Pr1eU=
|
||||
go.opentelemetry.io/otel/oteltest v0.20.0/go.mod h1:L7bgKf9ZB7qCwT9Up7i9/pn0PWIa9FqQ2IQ8LoxiGnw=
|
||||
go.opentelemetry.io/otel/sdk v0.20.0/go.mod h1:g/IcepuwNsoiX5Byy2nNV0ySUF1em498m7hBWC279Yc=
|
||||
go.opentelemetry.io/otel/trace v0.20.0/go.mod h1:6GjCW8zgDjwGHGa6GkyeB8+/5vjT16gUEi0Nf1iBdgw=
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4 h1:wviDUSmtheHRBfoY8B9U8ELl2USoXi2YFwdGdpIIkzI=
|
||||
golang.org/x/crypto v0.0.0-20180608092829-8ac0e0d97ce4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
|
||||
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b h1:QAqMVf3pSa6eeTsuklijukjXBlj7Es2QQplab+/RbQ4=
|
||||
golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/exp v0.0.0-20200513190911-00229845015e/go.mod h1:4M0jN8W1tt0AVLNr8HDosyJCDCDuyL9N9+3m7wDWgKw=
|
||||
golang.org/x/exp v0.0.0-20211123021643-48cbe7f80d7c/go.mod h1:b9TAUYHmRtqA6klRHApnXMnj+OyLce4yF5cZCUbk2ps=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPFgVGd+z1DZwjfRu4d0I=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mobile v0.0.0-20201217150744-e6ae53a27f4f/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd h1:nTDtHvHSdCn1m6ITfMRqtOd/9+7a3s8RBNOZ3eYZzJA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190327091125-710a502c58a2/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210909193231-528a39cd75f3/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab h1:rfJ1bsoJQQIAoAxTxB7bme+vHrNkRw8CqfsYh9w54cw=
|
||||
golang.org/x/sys v0.0.0-20211123173158-ef496fb156ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c h1:fqgJT0MGcGpPgpWU7VRdRjuArfcOvC4AoJmILihzhDg=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190921001708-c4c64cad1fd0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200117012304-6edc0a871e69/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/genproto v0.0.0-20180518175338-11a468237815/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f h1:FU37niK8AQ59mHcskRyQL7H0ErSeNh650vdcj8HqdSI=
|
||||
google.golang.org/genproto v0.0.0-20181004005441-af9cb2a35e7f/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s=
|
||||
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||
google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84/go.mod h1:SzzZ/N+nwJDaO1kznhnlzqS8ocJICar6hYhVyhi++24=
|
||||
google.golang.org/grpc v1.12.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9 h1:7z2uVWwn7oVeeugY1DtlPAy5H+KYgB1KeKTnqjNatLo=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNjB2u4i700xBkIT4e0=
|
||||
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo=
|
||||
gopkg.in/ini.v1 v1.41.0 h1:Ka3ViY6gNYSKiVy71zXBEqKplnV35ImDLVG+8uoIklE=
|
||||
gopkg.in/ini.v1 v1.41.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79 h1:FpCr9V8wuOei4BAen+93HtVJ+XSi+KPbaPKm0Vj5R64=
|
||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
|
||||
gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE=
|
||||
gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y=
|
||||
gopkg.in/ini.v1 v1.48.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
|
||||
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
|
||||
gopkg.in/nullbio/null.v6 v6.0.0-20161116030900-40264a2e6b79/go.mod h1:gWkaRU7CoXpezCBWfWjm3999QqS+1pYPXGbqQCTMzo8=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.1.3/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU=
|
||||
+15
-14
@@ -3,12 +3,13 @@ package lbrycrd
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"golang.org/x/crypto/ripemd160"
|
||||
|
||||
"github.com/lbryio/lbcd/chaincfg"
|
||||
"github.com/lbryio/lbcutil"
|
||||
"github.com/lbryio/lbcutil/base58"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
// DecodeAddress decodes the string encoding of an address and returns
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
// The bitcoin network the address is associated with is extracted if possible.
|
||||
// When the address does not encode the network, such as in the case of a raw
|
||||
// public key, the address will be associated with the passed defaultNet.
|
||||
func DecodeAddress(addr string, defaultNet *chaincfg.Params) (btcutil.Address, error) {
|
||||
func DecodeAddress(addr string, defaultNet *chaincfg.Params) (lbcutil.Address, error) {
|
||||
// Serialized public keys are either 65 bytes (130 hex chars) if
|
||||
// uncompressed/hybrid or 33 bytes (66 hex chars) if compressed.
|
||||
if len(addr) == 130 || len(addr) == 66 {
|
||||
@@ -25,16 +26,16 @@ func DecodeAddress(addr string, defaultNet *chaincfg.Params) (btcutil.Address, e
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return btcutil.NewAddressPubKey(serializedPubKey, defaultNet)
|
||||
return lbcutil.NewAddressPubKey(serializedPubKey, defaultNet)
|
||||
}
|
||||
|
||||
// Switch on decoded length to determine the type.
|
||||
decoded, netID, err := base58.CheckDecode(addr)
|
||||
if err != nil {
|
||||
if err == base58.ErrChecksum {
|
||||
return nil, btcutil.ErrChecksumMismatch
|
||||
return nil, lbcutil.ErrChecksumMismatch
|
||||
}
|
||||
return nil, errors.Err("decoded address is of unknown format")
|
||||
return nil, errors.WithStack(errors.Newf("decoded address[%s] is of unknown format even with default chainparams[%s]", addr, defaultNet.Name))
|
||||
}
|
||||
|
||||
switch len(decoded) {
|
||||
@@ -43,16 +44,16 @@ func DecodeAddress(addr string, defaultNet *chaincfg.Params) (btcutil.Address, e
|
||||
isP2SH := chaincfg.IsScriptHashAddrID(netID)
|
||||
switch hash160 := decoded; {
|
||||
case isP2PKH && isP2SH:
|
||||
return nil, btcutil.ErrAddressCollision
|
||||
return nil, lbcutil.ErrAddressCollision
|
||||
case isP2PKH:
|
||||
return btcutil.NewAddressPubKeyHash(hash160, &chaincfg.Params{PubKeyHashAddrID: netID})
|
||||
return lbcutil.NewAddressPubKeyHash(hash160, &chaincfg.Params{PubKeyHashAddrID: netID})
|
||||
case isP2SH:
|
||||
return btcutil.NewAddressScriptHashFromHash(hash160, &chaincfg.Params{ScriptHashAddrID: netID})
|
||||
return lbcutil.NewAddressScriptHashFromHash(hash160, &chaincfg.Params{ScriptHashAddrID: netID})
|
||||
default:
|
||||
return nil, btcutil.ErrUnknownAddressType
|
||||
return nil, lbcutil.ErrUnknownAddressType
|
||||
}
|
||||
|
||||
default:
|
||||
return nil, errors.Err("decoded address is of unknown size")
|
||||
return nil, errors.WithStack(errors.New("decoded address is of unknown size"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package lbrycrd
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDecodeAddress(t *testing.T) {
|
||||
addr := "bMUxfQVUeDi7ActVeZJZHzHKBceai7kHha"
|
||||
btcAddr, err := DecodeAddress(addr, &MainNetParams)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
println(btcAddr.EncodeAddress())
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package lbrycrd_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/lbrycrd"
|
||||
"github.com/lbryio/lbry.go/v3/lbrycrd"
|
||||
)
|
||||
|
||||
var claimIdTests = []struct {
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"github.com/lbryio/lbry.go/v3/schema/keys"
|
||||
c "github.com/lbryio/lbry.go/v3/schema/stake"
|
||||
|
||||
"github.com/lbryio/lbcd/btcec"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
func NewChannel() (*c.Helper, *btcec.PrivateKey, error) {
|
||||
claimChannel := new(pb.Claim_Channel)
|
||||
channel := new(pb.Channel)
|
||||
claimChannel.Channel = channel
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = claimChannel
|
||||
|
||||
privateKey, err := btcec.NewPrivateKey(btcec.S256())
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithStack(err)
|
||||
}
|
||||
pubkeyBytes, err := keys.PublicKeyToDER(privateKey.PubKey())
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
helper := c.Helper{Claim: pbClaim}
|
||||
helper.Version = c.NoSig
|
||||
helper.Claim.GetChannel().PublicKey = pubkeyBytes
|
||||
helper.Claim.Tags = []string{}
|
||||
coverSrc := new(pb.Source)
|
||||
helper.Claim.GetChannel().Cover = coverSrc
|
||||
helper.Claim.Languages = []*pb.Language{}
|
||||
thumbnailSrc := new(pb.Source)
|
||||
helper.Claim.Thumbnail = thumbnailSrc
|
||||
helper.Claim.Locations = []*pb.Location{}
|
||||
|
||||
return &helper, privateKey, nil
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
c "github.com/lbryio/lbry.go/v3/schema/stake"
|
||||
pb "github.com/lbryio/types/v2/go"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/lbryio/lbcd/btcec"
|
||||
"github.com/lbryio/lbcd/wire"
|
||||
)
|
||||
|
||||
func NewImageStreamClaim() (*c.Helper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
image := new(pb.Stream_Image)
|
||||
image.Image = new(pb.Image)
|
||||
stream.Type = image
|
||||
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.Helper{Claim: pbClaim}
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func NewVideoStreamClaim() (*c.Helper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
video := new(pb.Stream_Video)
|
||||
video.Video = new(pb.Video)
|
||||
stream.Type = video
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.Helper{Claim: pbClaim}
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func NewStreamClaim(title, description string) (*c.Helper, error) {
|
||||
streamClaim := new(pb.Claim_Stream)
|
||||
stream := new(pb.Stream)
|
||||
streamClaim.Stream = stream
|
||||
|
||||
pbClaim := new(pb.Claim)
|
||||
pbClaim.Type = streamClaim
|
||||
|
||||
helper := c.Helper{Claim: pbClaim}
|
||||
helper.Claim.Title = title
|
||||
helper.Claim.Description = description
|
||||
|
||||
return &helper, nil
|
||||
}
|
||||
|
||||
func SignClaim(rawTx *wire.MsgTx, privKey btcec.PrivateKey, claim, channel *c.Helper, channelClaimID string) error {
|
||||
claimIDHexBytes, err := hex.DecodeString(channelClaimID)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
claim.Version = c.WithSig
|
||||
claim.ClaimID = rev(claimIDHexBytes)
|
||||
hash, err := c.GetOutpointHash(rawTx.TxIn[0].PreviousOutPoint.Hash.String(), rawTx.TxIn[0].PreviousOutPoint.Index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sig, err := c.Sign(privKey, *channel, *claim, hash)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lbrySig, err := sig.LBRYSDKEncode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
claim.Signature = lbrySig
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
+251
-49
@@ -1,16 +1,22 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/lbryio/lbry.go/extras/errors"
|
||||
c "github.com/lbryio/lbry.go/v3/schema/stake"
|
||||
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/lbryio/lbcd/btcec"
|
||||
"github.com/lbryio/lbcd/btcjson"
|
||||
"github.com/lbryio/lbcd/chaincfg"
|
||||
"github.com/lbryio/lbcd/chaincfg/chainhash"
|
||||
"github.com/lbryio/lbcd/rpcclient"
|
||||
"github.com/lbryio/lbcd/wire"
|
||||
"github.com/lbryio/lbcutil"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/go-ini/ini"
|
||||
)
|
||||
|
||||
@@ -28,10 +34,53 @@ var MainNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: 0x55,
|
||||
ScriptHashAddrID: 0x7a,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "not-used", // we don't have this (yet)
|
||||
GenesisHash: &GenesisHash,
|
||||
Bech32HRPSegwit: "lbc",
|
||||
//WitnessPubKeyHashAddrID: , // i cant find these in bitcoin codebase either
|
||||
//WitnessScriptHashAddrID:,
|
||||
GenesisHash: &GenesisHash,
|
||||
Name: "mainnet",
|
||||
Net: wire.BitcoinNet(0xfae4aaf1),
|
||||
DefaultPort: "9246",
|
||||
BIP0034Height: 1,
|
||||
BIP0065Height: 200000,
|
||||
BIP0066Height: 200000,
|
||||
}
|
||||
|
||||
const (
|
||||
lbrycrdMainPubkeyPrefix = byte(85)
|
||||
lbrycrdMainScriptPrefix = byte(122)
|
||||
lbrycrdTestnetPubkeyPrefix = byte(111)
|
||||
lbrycrdTestnetScriptPrefix = byte(196)
|
||||
lbrycrdRegtestPubkeyPrefix = byte(111)
|
||||
lbrycrdRegtestScriptPrefix = byte(196)
|
||||
|
||||
LbrycrdMain = "lbrycrd_main"
|
||||
LbrycrdTestnet = "lbrycrd_testnet"
|
||||
LbrycrdRegtest = "lbrycrd_regtest"
|
||||
)
|
||||
|
||||
var mainNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdMainPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdMainScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
}
|
||||
|
||||
var testNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdTestnetPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdTestnetScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "tlbc",
|
||||
}
|
||||
|
||||
var regTestNetParams = chaincfg.Params{
|
||||
PubKeyHashAddrID: lbrycrdRegtestPubkeyPrefix,
|
||||
ScriptHashAddrID: lbrycrdRegtestScriptPrefix,
|
||||
PrivateKeyID: 0x1c,
|
||||
Bech32HRPSegwit: "rlbc",
|
||||
}
|
||||
|
||||
var ChainParamsMap = map[string]chaincfg.Params{LbrycrdMain: mainNetParams, LbrycrdTestnet: testNetParams, LbrycrdRegtest: regTestNetParams}
|
||||
|
||||
func init() {
|
||||
// Register lbrycrd network
|
||||
err := chaincfg.Register(&MainNetParams)
|
||||
@@ -46,16 +95,16 @@ type Client struct {
|
||||
}
|
||||
|
||||
// New initializes a new Client
|
||||
func New(lbrycrdURL string) (*Client, error) {
|
||||
func New(lbrycrdURL string, chainParams string) (*Client, error) {
|
||||
// Connect to local bitcoin core RPC server using HTTP POST mode.
|
||||
|
||||
u, err := url.Parse(lbrycrdURL)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if u.User == nil {
|
||||
return nil, errors.Err("no userinfo")
|
||||
return nil, errors.WithStack(errors.New("no userinfo"))
|
||||
}
|
||||
|
||||
password, _ := u.User.Password()
|
||||
@@ -64,19 +113,20 @@ func New(lbrycrdURL string) (*Client, error) {
|
||||
Host: u.Host,
|
||||
User: u.User.Username(),
|
||||
Pass: password,
|
||||
Params: chainParams,
|
||||
HTTPPostMode: true, // Bitcoin core only supports HTTP POST mode
|
||||
DisableTLS: true, // Bitcoin core does not provide TLS by default
|
||||
}
|
||||
// Notice the notification parameter is nil since notifications are not supported in HTTP POST mode.
|
||||
client, err := rpcclient.New(connCfg, nil)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
// make sure lbrycrd is running and responsive
|
||||
_, err = client.GetInfo()
|
||||
_, err = client.GetBlockChainInfo()
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return &Client{client}, nil
|
||||
@@ -87,60 +137,36 @@ func NewWithDefaultURL() (*Client, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(url)
|
||||
return New(url, "")
|
||||
}
|
||||
|
||||
var errInsufficientFunds = errors.Base("insufficient funds")
|
||||
var errInsufficientFunds = errors.New("insufficient funds")
|
||||
|
||||
// SimpleSend is a convenience function to send credits to an address (0 min confirmations)
|
||||
func (c *Client) SimpleSend(toAddress string, amount float64) (*chainhash.Hash, error) {
|
||||
decodedAddress, err := DecodeAddress(toAddress, &MainNetParams)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
lbcAmount, err := btcutil.NewAmount(amount)
|
||||
lbcAmount, err := lbcutil.NewAmount(amount)
|
||||
if err != nil {
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
hash, err := c.Client.SendFromMinConf("", decodedAddress, lbcAmount, 0)
|
||||
hash, err := c.Client.SendToAddress(decodedAddress, lbcAmount)
|
||||
if err != nil {
|
||||
if err.Error() == "-6: Insufficient funds" {
|
||||
err = errors.Err(errInsufficientFunds)
|
||||
err = errors.WithStack(errInsufficientFunds)
|
||||
}
|
||||
return nil, errors.Err(err)
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
return hash, nil
|
||||
}
|
||||
|
||||
//func (c *Client) SendWithSplit(toAddress string, amount float64, numUTXOs int) (*chainhash.Hash, error) {
|
||||
// decodedAddress, err := DecodeAddress(toAddress, &MainNetParams)
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, 0)
|
||||
// }
|
||||
//
|
||||
// amountPerAddress, err := btcutil.NewAmount(amount / float64(numUTXOs))
|
||||
// if err != nil {
|
||||
// return nil, errors.Wrap(err, 0)
|
||||
// }
|
||||
//
|
||||
// amounts := map[btcutil.Address]btcutil.Amount{}
|
||||
// for i := 0; i < numUTXOs; i++ {
|
||||
// addr := decodedAddress // to give it a new address, so
|
||||
// amounts[addr] = amountPerAddress
|
||||
// }
|
||||
//
|
||||
// hash, err := c.Client.SendManyMinConf("", amounts, 0)
|
||||
// if err != nil && err.Error() == "-6: Insufficient funds" {
|
||||
// err = errors.Wrap(errInsufficientFunds, 0)
|
||||
// }
|
||||
// return hash, errors.Wrap(err, 0)
|
||||
//}
|
||||
|
||||
func getLbrycrdURLFromConfFile() (string, error) {
|
||||
if os.Getenv("HOME") == "" {
|
||||
return "", errors.Err("no $HOME var found")
|
||||
return "", errors.WithStack(errors.New("no $HOME var found"))
|
||||
}
|
||||
|
||||
defaultConfFile := os.Getenv("HOME") + "/.lbrycrd/lbrycrd.conf"
|
||||
@@ -148,17 +174,17 @@ func getLbrycrdURLFromConfFile() (string, error) {
|
||||
defaultConfFile = os.Getenv("HOME") + "/.lbrycrd_regtest/lbrycrd.conf"
|
||||
}
|
||||
if _, err := os.Stat(defaultConfFile); os.IsNotExist(err) {
|
||||
return "", errors.Err("default lbrycrd conf file not found")
|
||||
return "", errors.WithStack(errors.New("default lbrycrd conf file not found"))
|
||||
}
|
||||
|
||||
cfg, err := ini.Load(defaultConfFile)
|
||||
if err != nil {
|
||||
return "", errors.Err(err)
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
section, err := cfg.GetSection("")
|
||||
if err != nil {
|
||||
return "", errors.Err(err)
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
username := section.Key("rpcuser").String()
|
||||
@@ -179,3 +205,179 @@ func getLbrycrdURLFromConfFile() (string, error) {
|
||||
|
||||
return "rpc://" + userpass + host + ":" + port, nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateBaseRawTx(inputs []btcjson.TransactionInput, change float64) (*wire.MsgTx, error) {
|
||||
addresses := make(map[lbcutil.Address]lbcutil.Amount)
|
||||
changeAddress, err := c.GetNewAddress("")
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
changeAmount, err := lbcutil.NewAmount(change)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
addresses[changeAddress] = changeAmount
|
||||
lockTime := int64(0)
|
||||
return c.CreateRawTransaction(inputs, addresses, &lockTime)
|
||||
}
|
||||
|
||||
func (c *Client) GetEmptyTx(totalOutputSpend float64) (*wire.MsgTx, error) {
|
||||
totalFees := 0.1
|
||||
unspentResults, err := c.ListUnspentMin(1)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
finder := newOutputFinder(unspentResults)
|
||||
|
||||
outputs, err := finder.nextBatch(totalOutputSpend + totalFees)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(outputs) == 0 {
|
||||
return nil, errors.WithStack(errors.New("Not enough spendable outputs to create transaction"))
|
||||
}
|
||||
inputs := make([]btcjson.TransactionInput, len(outputs))
|
||||
var totalInputSpend float64
|
||||
for i, output := range outputs {
|
||||
inputs[i] = btcjson.TransactionInput{Txid: output.TxID, Vout: output.Vout}
|
||||
totalInputSpend = totalInputSpend + output.Amount
|
||||
}
|
||||
|
||||
change := totalInputSpend - totalOutputSpend - totalFees
|
||||
return c.CreateBaseRawTx(inputs, change)
|
||||
}
|
||||
|
||||
func (c *Client) SignTxAndSend(rawTx *wire.MsgTx) (*chainhash.Hash, error) {
|
||||
signedTx, allInputsSigned, err := c.SignRawTransaction(rawTx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
if !allInputsSigned {
|
||||
return nil, errors.WithStack(errors.New("Not all inputs for the tx could be signed!"))
|
||||
}
|
||||
|
||||
return c.SendRawTransaction(signedTx, false)
|
||||
}
|
||||
|
||||
type ScriptType int
|
||||
|
||||
const (
|
||||
ClaimName ScriptType = iota
|
||||
ClaimUpdate
|
||||
ClaimSupport
|
||||
)
|
||||
|
||||
func (c *Client) AddStakeToTx(rawTx *wire.MsgTx, claim *c.Helper, name string, claimAmount float64, scriptType ScriptType) error {
|
||||
|
||||
address, err := c.GetNewAddress("")
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
amount, err := lbcutil.NewAmount(claimAmount)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
value, err := claim.CompileValue()
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
var claimID string
|
||||
if len(claim.ClaimID) > 0 {
|
||||
claimID = hex.EncodeToString(rev(claim.ClaimID))
|
||||
}
|
||||
var script []byte
|
||||
switch scriptType {
|
||||
case ClaimName:
|
||||
script, err = GetClaimNamePayoutScript(name, value, address)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
case ClaimUpdate:
|
||||
script, err = GetUpdateClaimPayoutScript(name, claimID, value, address)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
case ClaimSupport:
|
||||
script, err = GetUpdateClaimPayoutScript(name, claimID, value, address)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
rawTx.AddTxOut(wire.NewTxOut(int64(amount), script))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) CreateChannel(name string, amount float64) (*c.Helper, *btcec.PrivateKey, error) {
|
||||
channel, key, err := NewChannel()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
rawTx, err := c.GetEmptyTx(amount)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = c.AddStakeToTx(rawTx, channel, name, amount, ClaimName)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
_, err = c.SignTxAndSend(rawTx)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return channel, key, nil
|
||||
}
|
||||
|
||||
func (c *Client) SupportClaim(name, claimID, address, blockchainName string, claimAmount float64) (*chainhash.Hash, error) {
|
||||
const DefaultFeePerSupport = float64(0.0001)
|
||||
unspentResults, err := c.ListUnspentMin(1)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
finder := newOutputFinder(unspentResults)
|
||||
outputs, err := finder.nextBatch(claimAmount + DefaultFeePerSupport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(outputs) == 0 {
|
||||
return nil, errors.WithStack(errors.New("Not enough spendable outputs to create transaction"))
|
||||
}
|
||||
inputs := make([]btcjson.TransactionInput, len(outputs))
|
||||
|
||||
var totalInputSpend float64
|
||||
for i, output := range outputs {
|
||||
inputs[i] = btcjson.TransactionInput{Txid: output.TxID, Vout: output.Vout}
|
||||
totalInputSpend = totalInputSpend + output.Amount
|
||||
}
|
||||
|
||||
change := totalInputSpend - claimAmount - DefaultFeePerSupport
|
||||
rawTx, err := c.CreateBaseRawTx(inputs, change)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chainParams, ok := ChainParamsMap[blockchainName]
|
||||
if !ok {
|
||||
return nil, errors.WithStack(errors.Newf("invalid blockchain name %s", blockchainName))
|
||||
}
|
||||
decodedAddress, err := DecodeAddress(address, &chainParams)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
amount, err := lbcutil.NewAmount(claimAmount)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
script, err := GetClaimSupportPayoutScript(name, claimID, decodedAddress)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
rawTx.AddTxOut(wire.NewTxOut(int64(amount), script))
|
||||
|
||||
return c.SignTxAndSend(rawTx)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package lbrycrd_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/lbryio/lbry.go/v3/lbrycrd"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
_, err := lbrycrd.New("rpc://xxxx:yyzy@localhost:9245", "")
|
||||
if err == nil {
|
||||
t.Errorf("wtf")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"github.com/cockroachdb/errors"
|
||||
"github.com/lbryio/lbcd/btcjson"
|
||||
)
|
||||
|
||||
type outputFinder struct {
|
||||
unspent []btcjson.ListUnspentResult
|
||||
lastChecked int
|
||||
}
|
||||
|
||||
func newOutputFinder(unspentResults []btcjson.ListUnspentResult) *outputFinder {
|
||||
return &outputFinder{unspent: unspentResults, lastChecked: -1}
|
||||
}
|
||||
|
||||
func (f *outputFinder) nextBatch(minAmount float64) ([]btcjson.ListUnspentResult, error) {
|
||||
var batch []btcjson.ListUnspentResult
|
||||
var lbcBatched float64
|
||||
for i, unspent := range f.unspent {
|
||||
if i > f.lastChecked {
|
||||
if unspent.Spendable {
|
||||
batch = append(batch, unspent)
|
||||
lbcBatched = lbcBatched + unspent.Amount
|
||||
}
|
||||
}
|
||||
if lbcBatched >= minAmount {
|
||||
f.lastChecked = i
|
||||
break
|
||||
}
|
||||
if i == len(f.unspent)-1 {
|
||||
return nil, errors.WithStack(errors.Newf("Not enough unspent outputs to spend %d on supports.", minAmount))
|
||||
}
|
||||
}
|
||||
|
||||
return batch, nil
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
package lbrycrd
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lbryio/lbcd/txscript"
|
||||
"github.com/lbryio/lbcutil"
|
||||
|
||||
"github.com/cockroachdb/errors"
|
||||
)
|
||||
|
||||
func GetClaimSupportPayoutScript(name, claimid string, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_SUPPORT_CLAIM <name> <claimid> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_SUPPORTCLAIM). //OP_SUPPORT_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
|
||||
}
|
||||
|
||||
func GetClaimNamePayoutScript(name string, value []byte, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_CLAIM_NAME <name> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_CLAIMNAME). //OP_CLAIMNAME
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
|
||||
func GetUpdateClaimPayoutScript(name, claimid string, value []byte, address lbcutil.Address) ([]byte, error) {
|
||||
//OP_UPDATE_CLAIM <name> <claimid> <value> OP_2DROP OP_DROP OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
|
||||
pkscript, err := txscript.PayToAddrScript(address)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
bytes, err := hex.DecodeString(claimid)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return txscript.NewScriptBuilder().
|
||||
AddOp(txscript.OP_UPDATECLAIM). //OP_UPDATE_CLAIM
|
||||
AddData([]byte(name)). //<name>
|
||||
AddData(rev(bytes)). //<claimid>
|
||||
AddData(value). //<value>
|
||||
AddOp(txscript.OP_2DROP). //OP_2DROP
|
||||
AddOp(txscript.OP_DROP). //OP_DROP
|
||||
AddOps(pkscript). //OP_DUP OP_HASH160 <address> OP_EQUALVERIFY OP_CHECKSIG
|
||||
Script()
|
||||
}
|
||||
|
||||
// IsClaimNameScript returns true if the script for the vout contains the OP_CLAIM_NAME code.
|
||||
func IsClaimNameScript(script []byte) bool {
|
||||
return len(script) > 0 && script[0] == txscript.OP_CLAIMNAME
|
||||
}
|
||||
|
||||
// IsClaimUpdateScript returns true if the script for the vout contains the OP_CLAIM_UPDATE code.
|
||||
func IsClaimUpdateScript(script []byte) bool {
|
||||
return len(script) > 0 && script[0] == txscript.OP_UPDATECLAIM
|
||||
}
|
||||
|
||||
// ParseClaimNameScript parses a script for the claim of a name.
|
||||
func ParseClaimNameScript(script []byte) (name string, value []byte, pubkeyscript []byte, err error) {
|
||||
// Already validated by blockchain so can be assumed
|
||||
// opClaimName Name Value OP_2DROP OP_DROP pubkeyscript
|
||||
nameBytesToRead := int(script[1])
|
||||
nameStart := 2
|
||||
if nameBytesToRead == txscript.OP_PUSHDATA1 {
|
||||
nameBytesToRead = int(script[2])
|
||||
nameStart = 3
|
||||
} else if nameBytesToRead > txscript.OP_PUSHDATA1 {
|
||||
return "", nil, nil, errors.WithStack(errors.New("bytes to read is more than next byte"))
|
||||
}
|
||||
nameEnd := nameStart + nameBytesToRead
|
||||
name = string(script[nameStart:nameEnd])
|
||||
dataPushType := int(script[nameEnd])
|
||||
valueBytesToRead := int(script[nameEnd])
|
||||
valueStart := nameEnd + 1
|
||||
if dataPushType == txscript.OP_PUSHDATA1 {
|
||||
valueBytesToRead = int(script[nameEnd+1])
|
||||
valueStart = nameEnd + 2
|
||||
} else if dataPushType == txscript.OP_PUSHDATA2 {
|
||||
valueStart = nameEnd + 3
|
||||
valueBytesToRead = int(binary.LittleEndian.Uint16(script[nameEnd+1 : valueStart]))
|
||||
} else if dataPushType == txscript.OP_PUSHDATA4 {
|
||||
valueStart = nameEnd + 5
|
||||
valueBytesToRead = int(binary.LittleEndian.Uint32(script[nameEnd+2 : valueStart]))
|
||||
}
|
||||
valueEnd := valueStart + valueBytesToRead
|
||||
value = script[valueStart:valueEnd]
|
||||
pksStart := valueEnd + 2 // +2 to ignore OP_2DROP and OP_DROP
|
||||
pubkeyscript = script[pksStart:] //Remainder is always pubkeyscript
|
||||
|
||||
return name, value, pubkeyscript, err
|
||||
}
|
||||
|
||||
// ParseClaimUpdateScript parses a script for an update of a claim.
|
||||
func ParseClaimUpdateScript(script []byte) (name string, claimid string, value []byte, pubkeyscript []byte, err error) {
|
||||
// opUpdateClaim Name ClaimID Value OP_2DROP OP_2DROP pubkeyscript
|
||||
|
||||
//Name
|
||||
nameBytesToRead := int(script[1])
|
||||
nameStart := 2
|
||||
if nameBytesToRead == txscript.OP_PUSHDATA1 {
|
||||
nameBytesToRead = int(script[2])
|
||||
nameStart = 3
|
||||
} else if nameBytesToRead > txscript.OP_PUSHDATA1 {
|
||||
err = errors.WithStack(errors.New("ParseClaimUpdateScript: Bytes to read is more than next byte! "))
|
||||
return
|
||||
}
|
||||
nameEnd := nameStart + nameBytesToRead
|
||||
name = string(script[nameStart:nameEnd])
|
||||
|
||||
//ClaimID
|
||||
claimidBytesToRead := int(script[nameEnd])
|
||||
claimidStart := nameEnd + 1
|
||||
claimidEnd := claimidStart + claimidBytesToRead
|
||||
bytes := rev(script[claimidStart:claimidEnd])
|
||||
claimid = hex.EncodeToString(bytes)
|
||||
|
||||
//Value
|
||||
dataPushType := int(script[claimidEnd])
|
||||
valueBytesToRead := int(script[claimidEnd])
|
||||
valueStart := claimidEnd + 1
|
||||
if dataPushType == txscript.OP_PUSHDATA1 {
|
||||
valueBytesToRead = int(script[claimidEnd+1])
|
||||
valueStart = claimidEnd + 2
|
||||
} else if dataPushType == txscript.OP_PUSHDATA2 {
|
||||
valueStart = claimidEnd + 3
|
||||
valueBytesToRead = int(binary.LittleEndian.Uint16(script[claimidEnd+1 : valueStart]))
|
||||
} else if dataPushType == txscript.OP_PUSHDATA4 {
|
||||
valueStart = claimidEnd + 5
|
||||
valueBytesToRead = int(binary.LittleEndian.Uint32(script[claimidEnd+2 : valueStart]))
|
||||
}
|
||||
valueEnd := valueStart + valueBytesToRead
|
||||
value = script[valueStart:valueEnd]
|
||||
|
||||
//PublicKeyScript
|
||||
pksStart := valueEnd + 2 // +2 to ignore OP_2DROP and OP_DROP
|
||||
pubkeyscript = script[pksStart:] //Remainder is always pubkeyscript
|
||||
|
||||
return name, claimid, value, pubkeyscript, err
|
||||
}
|
||||
Loaded 100 of 140 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user