-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
682a00d
commit 50e9ea7
Showing
31 changed files
with
721 additions
and
222 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,3 @@ | ||
// Package apl provides the datatypes for construction APL. They usually extend | ||
// the functionality of existing types from the `query` package. | ||
package apl |
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,22 @@ | ||
package apl | ||
|
||
import ( | ||
"net/url" | ||
) | ||
|
||
//go:generate ../../bin/stringer -type=Format -linecomment -output=format_string.go | ||
|
||
// Format represents the format of an APL query. | ||
type Format uint8 | ||
|
||
// All available query formats. | ||
const ( | ||
Legacy Format = iota // legacy | ||
) | ||
|
||
// EncodeValues implements `query.Encoder`. It is in place to encode the Format | ||
// into a string URL value because that's what the server expects. | ||
func (f Format) EncodeValues(key string, v *url.Values) error { | ||
v.Set(key, f.String()) | ||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,41 @@ | ||
package apl | ||
|
||
import ( | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestFormat_EncodeValues(t *testing.T) { | ||
tests := []struct { | ||
input Format | ||
exp string | ||
}{ | ||
{Legacy, "legacy"}, | ||
// {0, "Format(0)"}, // HINT(lukasmalkmus): Maybe we want to sort this out by raising an error? | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.input.String(), func(t *testing.T) { | ||
v := &url.Values{} | ||
err := tt.input.EncodeValues("test", v) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, tt.exp, v.Get("test")) | ||
}) | ||
} | ||
} | ||
|
||
func TestFormat_String(t *testing.T) { | ||
// Check outer bounds. | ||
// assert.Equal(t, Format(0).String(), "Format(0)") | ||
// assert.Contains(t, (Legacy - 1).String(), "Format(") | ||
assert.Contains(t, (Legacy + 1).String(), "Format(") | ||
|
||
for c := Legacy; c <= Legacy; c++ { | ||
s := c.String() | ||
assert.NotEmpty(t, s) | ||
assert.NotContains(t, s, "Format(") | ||
} | ||
} |
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,25 @@ | ||
package apl | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// Options specifies the optional parameters to APL query methods. | ||
type Options struct { | ||
// StartTime of the query. | ||
StartTime time.Time `url:"-"` | ||
// EndTime of the query. | ||
EndTime time.Time `url:"-"` | ||
|
||
// NoCache omits the query cache. | ||
NoCache bool `url:"nocache,omitempty"` | ||
// Save the query on the server, if set to `true`. The ID of the saved query | ||
// is returned with the query result as part of the response. | ||
// HINT(lukasmalkmus): The server automatically sets the query kind to "apl" | ||
// for queries going to the "/_apl" query endpoint. This allows us to set | ||
// any value for the `saveAsKind` query param. For user experience, we use a | ||
// bool here instead of forcing the user to set the value to `query.APL`. | ||
Save bool `url:"saveAsKind,omitempty"` | ||
// Format specifies the format of the APL query. Defaults to Legacy. | ||
Format Format `url:"format"` | ||
} |
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,12 @@ | ||
package apl | ||
|
||
import "github.com/axiomhq/axiom-go/axiom/query" | ||
|
||
// Result is the result of an APL query. It adds the APL query request alongside | ||
// the query result it created, making it a superset of `query.Result` | ||
type Result struct { | ||
// Request is the APL query request that created the result. | ||
Request *query.Query `json:"request"` | ||
|
||
*query.Result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.