-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This Boolean type is required in order to correctly serialize/de-serialize map keys that contain bools in accordance with the conjure spec.
- Loading branch information
Showing
69 changed files
with
20,019 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) 2020 Palantir Technologies. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package boolean | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
// Boolean is an alias for bool which implements serialization matching the conjure wire specification. | ||
// ref: https://github.com/palantir/conjure/blob/master/docs/spec/wire.md | ||
type Boolean bool | ||
|
||
// UnmarshalText implements encoding.TextUnmarshaler (used by encoding/json and others). | ||
func (b *Boolean) UnmarshalText(data []byte) error { | ||
bo, err := strconv.ParseBool(string(data)) | ||
if err != nil { | ||
return err | ||
} | ||
*b = Boolean(bo) | ||
return nil | ||
} | ||
|
||
// MarshalText implements encoding.TextMarshaler (used by encoding/json and others). | ||
func (b Boolean) MarshalText() ([]byte, error) { | ||
return []byte(strconv.FormatBool(bool(b))), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright (c) 2020 Palantir Technologies. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package boolean | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBoolean_Marshal(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
input bool | ||
output []byte | ||
}{ | ||
{ | ||
name: "false input", | ||
input: false, | ||
output: []byte(`"false"`), | ||
}, | ||
{ | ||
name: "true input", | ||
input: true, | ||
output: []byte(`"true"`), | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
out, err := json.Marshal(Boolean(tc.input)) | ||
require.NoError(t, err) | ||
require.Equal(t, out, tc.output) | ||
}) | ||
} | ||
} | ||
|
||
func TestBoolean_Unmarshal(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
input []byte | ||
output Boolean | ||
expectErr bool | ||
}{ | ||
{ | ||
name: "nil input", | ||
input: nil, | ||
output: false, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "empty input", | ||
input: []byte(`""`), | ||
output: false, | ||
expectErr: true, | ||
}, | ||
{ | ||
name: "false input", | ||
input: []byte(`"false"`), | ||
output: false, | ||
expectErr: false, | ||
}, | ||
{ | ||
name: "true input", | ||
input: []byte(`"true"`), | ||
output: true, | ||
expectErr: false, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var b Boolean | ||
err := json.Unmarshal(tc.input, &b) | ||
require.Equal(t, tc.expectErr, err != nil) | ||
require.Equal(t, b, tc.output) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/palantir/pkg/boolean | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/palantir/pkg v1.0.1 | ||
github.com/stretchr/testify v1.4.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/palantir/pkg v1.0.1 h1:ZbGUcc14N7xcZSY9cehQoiHHTm/BAZO5RJdlsNEtSbk= | ||
github.com/palantir/pkg v1.0.1/go.mod h1:Eo6Jl0UXfT+65sLXJOcU9duu0WPvKsWFXCb0dE5VWZs= | ||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= | ||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
checks: | ||
golint: | ||
filters: | ||
- value: "should have comment or be unexported" | ||
- value: "or a comment on this block" |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
distributionURL=https://palantir.bintray.com/releases/com/palantir/godel/godel/2.25.0/godel-2.25.0.tgz | ||
distributionSHA256=f9a58181cfc1c709e9ac4a763bce386fb4e0c5ad24a635120b7d592c60e10206 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
plugins: | ||
resolvers: | ||
- https://palantir.bintray.com/releases/{{GroupPath}}/{{Product}}/{{Version}}/{{Product}}-{{Version}}-{{OS}}-{{Arch}}.tgz | ||
plugins: | ||
- locator: | ||
id: com.palantir.godel-mod-plugin:mod-plugin:1.0.1 | ||
checksums: | ||
darwin-amd64: df22922bacfe4e4e7c255607a0aace176205f04ae001f3746276fcfab1780e01 | ||
linux-amd64: a2697b3d504bb37c2fd8831a66c7014927a6d94e4dfb9765b4764354370a1ab6 | ||
environment: | ||
GO111MODULE: "on" | ||
GOFLAGS: "-mod=vendor" | ||
exclude: | ||
names: | ||
- "\\..+" | ||
- "vendor" | ||
paths: | ||
- "godel" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
header: | | ||
// Copyright (c) {{YEAR}} Palantir Technologies. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. |
Empty file.
Oops, something went wrong.