a bit more testing
This commit is contained in:
@@ -5,7 +5,8 @@ import (
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/queryQueue"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -39,7 +40,7 @@ func (s *Service) Sync(ctx context.Context, doc *Document) error {
|
||||
return err
|
||||
}
|
||||
|
||||
queue, err := query.NewQueue(ctx, s.db, collector, results, doc.ID, doc.CleanVersion, doc.TextVersion)
|
||||
queue, err := queryQueue.New(ctx, s.db, collector, results, doc.ID, doc.CleanVersion, doc.TextVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -52,7 +53,7 @@ func (s *Service) Sync(ctx context.Context, doc *Document) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) getResults(ctx context.Context, id uuid.UUID, coll *collector.Collector) (*[]query.Result, error) {
|
||||
func (s *Service) getResults(ctx context.Context, id uuid.UUID, coll *collector.Collector) (*[]result.Result, error) {
|
||||
docID := database.MustToDBUUID(id)
|
||||
|
||||
results, err := s.db.ListResultsByDocumentID(ctx, repository.ListResultsByDocumentIDParams{
|
||||
@@ -64,18 +65,10 @@ func (s *Service) getResults(ctx context.Context, id uuid.UUID, coll *collector.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cleanResults := make([]query.Result, len(results))
|
||||
cleanResults := make([]result.Result, len(results))
|
||||
for index, dbResult := range results {
|
||||
cleanResults[index] = *s.parseResult(&dbResult)
|
||||
cleanResults[index] = *result.Parse(&dbResult)
|
||||
}
|
||||
|
||||
return &cleanResults, nil
|
||||
}
|
||||
|
||||
func (s *Service) parseResult(dbQuery *repository.ListResultsByDocumentIDRow) *query.Result {
|
||||
return &query.Result{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
QueryID: database.MustToUUID(dbQuery.Queryid),
|
||||
QueryVersion: dbQuery.Queryversion,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import (
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func New(db *repository.Queries) *Extractor {
|
||||
return &Extractor{db}
|
||||
}
|
||||
|
||||
func (e *Extractor) Process(ctx context.Context, queryId uuid.UUID, queryVersion int32, values *[]result.Value) (string, error) {
|
||||
func (e *Extractor) Process(ctx context.Context, query query.Query, values *[]result.Value) (string, error) {
|
||||
if len(*values) != 1 {
|
||||
return "", fmt.Errorf("JSON Extraction requires 1 result")
|
||||
}
|
||||
@@ -32,8 +32,8 @@ func (e *Extractor) Process(ctx context.Context, queryId uuid.UUID, queryVersion
|
||||
value := (*values)[0].Value
|
||||
|
||||
byteConfig, err := e.db.GetQueryConfig(ctx, repository.GetQueryConfigParams{
|
||||
Queryid: database.MustToDBUUID(queryId),
|
||||
Addedversion: queryVersion,
|
||||
Queryid: database.MustToDBUUID(query.ID),
|
||||
Addedversion: query.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
@@ -1,37 +1,47 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
)
|
||||
|
||||
func ParseDBQuery(dbQuery *repository.GetCollectorQueriesRow) (*Query, error) {
|
||||
t, err := ParseDBType(dbQuery.Type)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Query{
|
||||
ID: database.MustToUUID(dbQuery.Queryid),
|
||||
Type: ParseDBQueryType(dbQuery.Type.Querytype),
|
||||
Type: t,
|
||||
RequiredQueryID: database.MustToUUID(dbQuery.Requiredqueryid),
|
||||
Version: dbQuery.Queryversion.Int32,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ParseDBQueryType(qType repository.Querytype) QueryType {
|
||||
switch qType {
|
||||
func ParseDBType(qType repository.NullQuerytype) (Type, error) {
|
||||
if !qType.Valid {
|
||||
return TypeJsonExtractor, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
|
||||
switch qType.Querytype {
|
||||
case repository.QuerytypeJsonExtractor:
|
||||
return QueryTypeJsonExtractor
|
||||
return TypeJsonExtractor, nil
|
||||
default:
|
||||
return QueryTypeJsonExtractor
|
||||
return TypeJsonExtractor, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
}
|
||||
|
||||
func ToDBQueryType(t QueryType) repository.NullQuerytype {
|
||||
func ToDBQueryType(t Type) (repository.NullQuerytype, error) {
|
||||
var dbType repository.Querytype
|
||||
|
||||
switch t {
|
||||
case QueryTypeJsonExtractor:
|
||||
case TypeJsonExtractor:
|
||||
dbType = repository.QuerytypeJsonExtractor
|
||||
default:
|
||||
dbType = repository.QuerytypeJsonExtractor
|
||||
return repository.NullQuerytype{}, fmt.Errorf("invalid database query type")
|
||||
}
|
||||
|
||||
return repository.NullQuerytype{Querytype: dbType, Valid: true}
|
||||
return repository.NullQuerytype{Querytype: dbType, Valid: true}, nil
|
||||
}
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/queryProcessor"
|
||||
"gotemplate/internal/result"
|
||||
)
|
||||
|
||||
func (q *Queue) prepareResult(ctx context.Context, query Query, resultValues *[]result.Value) (string, error) {
|
||||
processor, err := q.getProcessor(query.Type)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return processor.Process(ctx, query.ID, query.Version, resultValues)
|
||||
}
|
||||
|
||||
func (q *Queue) getProcessor(queryType QueryType) (queryProcessor.Processor, error) {
|
||||
switch queryType {
|
||||
case QueryTypeJsonExtractor:
|
||||
return jsonextractor.New(q.db), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,28 @@
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type QueryType int
|
||||
type Type int
|
||||
|
||||
const (
|
||||
QueryTypeJsonExtractor = iota
|
||||
TypeJsonExtractor = iota
|
||||
)
|
||||
|
||||
type Query struct {
|
||||
ID uuid.UUID
|
||||
Type QueryType
|
||||
Type Type
|
||||
RequiredQueryID uuid.UUID
|
||||
Version int32
|
||||
}
|
||||
|
||||
type Result struct {
|
||||
ID uuid.UUID
|
||||
QueryID uuid.UUID
|
||||
QueryVersion int32
|
||||
type Processor interface {
|
||||
Process(ctx context.Context, query Query, values *[]result.Value) (string, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package queryProcessor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Processor interface {
|
||||
Process(ctx context.Context, queryId uuid.UUID, queryVersion int32, values *[]result.Value) (string, error)
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package query
|
||||
package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/query"
|
||||
)
|
||||
|
||||
func (q *Queue) getUnsyncedQueries() {
|
||||
@@ -35,9 +36,9 @@ func (c *Queue) getCollectorQueries(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cleanQueries := make([]Query, len(queries))
|
||||
cleanQueries := make([]query.Query, len(queries))
|
||||
for index, dbQuery := range queries {
|
||||
cleanQuery, err := ParseDBQuery(&dbQuery)
|
||||
cleanQuery, err := query.ParseDBQuery(&dbQuery)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -50,33 +51,33 @@ func (c *Queue) getCollectorQueries(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) Add(query *Query) {
|
||||
dependentQueries := []Query{}
|
||||
func (q *Queue) Add(qu *query.Query) {
|
||||
dependentQueries := []query.Query{}
|
||||
requiredIndex := -1
|
||||
|
||||
if q.unsyncedQueue == nil {
|
||||
q.unsyncedQueue = &[]Query{}
|
||||
q.unsyncedQueue = &[]query.Query{}
|
||||
} else {
|
||||
for index, entry := range *q.unsyncedQueue {
|
||||
if entry.ID == query.ID {
|
||||
if entry.ID == qu.ID {
|
||||
return
|
||||
}
|
||||
if entry.ID == query.RequiredQueryID {
|
||||
if entry.ID == qu.RequiredQueryID {
|
||||
requiredIndex = index
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, entry := range *q.collectorQueries {
|
||||
if entry.RequiredQueryID == query.ID {
|
||||
if entry.RequiredQueryID == qu.ID {
|
||||
dependentQueries = append(dependentQueries, entry)
|
||||
}
|
||||
}
|
||||
|
||||
if requiredIndex != -1 {
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex], append([]Query{*query}, (*q.unsyncedQueue)[requiredIndex:]...)...)
|
||||
*q.unsyncedQueue = append((*q.unsyncedQueue)[:requiredIndex], append([]query.Query{*qu}, (*q.unsyncedQueue)[requiredIndex:]...)...)
|
||||
} else {
|
||||
*q.unsyncedQueue = append([]Query{*query}, *q.unsyncedQueue...)
|
||||
*q.unsyncedQueue = append([]query.Query{*qu}, *q.unsyncedQueue...)
|
||||
}
|
||||
|
||||
for _, entry := range dependentQueries {
|
||||
@@ -1,9 +1,9 @@
|
||||
package query
|
||||
package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -27,10 +27,10 @@ func (q *Queue) Execute(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) executeQuery(ctx context.Context, query Query) error {
|
||||
func (q *Queue) executeQuery(ctx context.Context, qu query.Query) error {
|
||||
requiredQueryIDs := []uuid.UUID{}
|
||||
for _, entry := range *q.collectorQueries {
|
||||
if entry.ID == query.ID && entry.RequiredQueryID != uuid.Nil {
|
||||
if entry.ID == qu.ID && entry.RequiredQueryID != uuid.Nil {
|
||||
requiredQueryIDs = append(requiredQueryIDs, entry.RequiredQueryID)
|
||||
}
|
||||
}
|
||||
@@ -60,44 +60,14 @@ func (q *Queue) executeQuery(ctx context.Context, query Query) error {
|
||||
|
||||
cleanValues := make([]result.Value, len(values))
|
||||
for _, r := range values {
|
||||
cleanValue := result.ParseResultValue(r)
|
||||
cleanValues = append(cleanValues, cleanValue)
|
||||
cleanValue := result.ParseValue(&r)
|
||||
cleanValues = append(cleanValues, *cleanValue)
|
||||
}
|
||||
|
||||
err = q.getResult(ctx, query, &cleanValues)
|
||||
err = q.setResult(ctx, qu, &cleanValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) getResult(ctx context.Context, query Query, resultValues *[]result.Value) error {
|
||||
value, err := q.prepareResult(ctx, query, resultValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id := uuid.New()
|
||||
|
||||
err = q.db.SetResult(ctx, repository.SetResultParams{
|
||||
ID: database.MustToDBUUID(id),
|
||||
Queryid: database.MustToDBUUID(query.ID),
|
||||
Documentid: database.MustToDBUUID(q.documentId),
|
||||
Value: value,
|
||||
Cleanversion: q.cleanVersion,
|
||||
Textversion: q.textVersion,
|
||||
Queryversion: query.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*q.results = append(*q.results, Result{
|
||||
ID: id,
|
||||
QueryID: query.ID,
|
||||
QueryVersion: query.Version,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
)
|
||||
|
||||
func (q *Queue) setResult(ctx context.Context, qu query.Query, resultValues *[]result.Value) error {
|
||||
processor, err := q.getProcessor(qu.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
value, err := processor.Process(ctx, qu, resultValues)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
id, err := result.Store(ctx, q.db, &result.ResultStore{
|
||||
QueryID: qu.ID,
|
||||
DocumentID: q.documentId,
|
||||
Value: value,
|
||||
CleanVersion: q.cleanVersion,
|
||||
TextVersion: q.textVersion,
|
||||
QueryVersion: qu.Version,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*q.results = append(*q.results, result.Result{
|
||||
ID: id,
|
||||
QueryID: qu.ID,
|
||||
QueryVersion: qu.Version,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *Queue) getProcessor(queryType query.Type) (query.Processor, error) {
|
||||
switch queryType {
|
||||
case query.TypeJsonExtractor:
|
||||
return jsonextractor.New(q.db), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("attempting to process invalid query type")
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,19 @@
|
||||
package query
|
||||
package queryQueue
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/collector"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Queue struct {
|
||||
unsyncedQueue *[]Query
|
||||
collectorQueries *[]Query
|
||||
results *[]Result
|
||||
unsyncedQueue *[]query.Query
|
||||
collectorQueries *[]query.Query
|
||||
results *[]result.Result
|
||||
collector *collector.Collector
|
||||
db *repository.Queries
|
||||
cleanVersion int32
|
||||
@@ -19,7 +21,7 @@ type Queue struct {
|
||||
documentId uuid.UUID
|
||||
}
|
||||
|
||||
func NewQueue(ctx context.Context, db *repository.Queries, coll *collector.Collector, results *[]Result, docId uuid.UUID, cleanVersion int32, textVersion int32) (*Queue, error) {
|
||||
func New(ctx context.Context, db *repository.Queries, coll *collector.Collector, results *[]result.Result, docId uuid.UUID, cleanVersion int32, textVersion int32) (*Queue, error) {
|
||||
queue := Queue{
|
||||
db: db,
|
||||
results: results,
|
||||
@@ -39,6 +41,6 @@ func NewQueue(ctx context.Context, db *repository.Queries, coll *collector.Colle
|
||||
return &queue, nil
|
||||
}
|
||||
|
||||
func (q *Queue) GetQueue() []Query {
|
||||
func (q *Queue) GetQueue() []query.Query {
|
||||
return *q.unsyncedQueue
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
)
|
||||
|
||||
func ParseValue(result *repository.ListResultValuesByIDRow) *Value {
|
||||
return &Value{
|
||||
ID: database.MustToUUID(result.ID),
|
||||
QueryID: database.MustToUUID(result.Queryid),
|
||||
Value: result.Value,
|
||||
}
|
||||
}
|
||||
|
||||
func Parse(dbQuery *repository.ListResultsByDocumentIDRow) *Result {
|
||||
return &Result{
|
||||
ID: database.MustToUUID(dbQuery.ID),
|
||||
QueryID: database.MustToUUID(dbQuery.Queryid),
|
||||
QueryVersion: dbQuery.Queryversion,
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,49 @@
|
||||
package result
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Result struct {
|
||||
ID uuid.UUID
|
||||
QueryID uuid.UUID
|
||||
QueryVersion int32
|
||||
}
|
||||
|
||||
type Value struct {
|
||||
ID uuid.UUID
|
||||
QueryID uuid.UUID
|
||||
Value string
|
||||
}
|
||||
|
||||
func ParseResultValue(result repository.ListResultValuesByIDRow) Value {
|
||||
return Value{
|
||||
ID: database.MustToUUID(result.ID),
|
||||
QueryID: database.MustToUUID(result.Queryid),
|
||||
Value: result.Value,
|
||||
}
|
||||
type ResultStore struct {
|
||||
QueryID uuid.UUID
|
||||
DocumentID uuid.UUID
|
||||
Value string
|
||||
CleanVersion int32
|
||||
TextVersion int32
|
||||
QueryVersion int32
|
||||
}
|
||||
|
||||
func Store(ctx context.Context, db *repository.Queries, res *ResultStore) (uuid.UUID, error) {
|
||||
id := uuid.New()
|
||||
|
||||
err := db.SetResult(ctx, repository.SetResultParams{
|
||||
ID: database.MustToDBUUID(id),
|
||||
Queryid: database.MustToDBUUID(res.QueryID),
|
||||
Documentid: database.MustToDBUUID(res.DocumentID),
|
||||
Value: res.Value,
|
||||
Cleanversion: res.CleanVersion,
|
||||
Textversion: res.TextVersion,
|
||||
Queryversion: res.QueryVersion,
|
||||
})
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ vars:
|
||||
tasks:
|
||||
unit:
|
||||
cmds:
|
||||
- mkdir -p {{.CONTEXT}}/{{.OUT_DIR}}
|
||||
- mkdir -p {{.CONTEXT}}/{{.OUT_DIR}}
|
||||
- go test {{.CONTEXT}}/test/unit/... -coverpkg={{.CONTEXT}}/internal/...,{{.CONTEXT}}/pkg/... -coverprofile={{.COVERAGE_FILE_WITH_CONTEXT}}
|
||||
unit:coverage:
|
||||
deps:
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
jsonextractor "gotemplate/internal/jsonExtractor"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/result"
|
||||
"testing"
|
||||
|
||||
@@ -28,8 +29,12 @@ func TestJSONProcess(t *testing.T) {
|
||||
|
||||
extractor := jsonextractor.New(queries)
|
||||
|
||||
queryID := uuid.New()
|
||||
queryVersion := int32(1)
|
||||
query := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: query.TypeJsonExtractor,
|
||||
RequiredQueryID: uuid.Nil,
|
||||
Version: int32(1),
|
||||
}
|
||||
entryValue := "value"
|
||||
|
||||
jsonString := fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||
@@ -39,13 +44,13 @@ func TestJSONProcess(t *testing.T) {
|
||||
|
||||
config := "{\"path\":\"key\"}"
|
||||
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err := extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err := extractor.Process(ctx, query, values)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, entryValue, value)
|
||||
|
||||
@@ -54,13 +59,13 @@ func TestJSONProcess(t *testing.T) {
|
||||
values = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
}
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err = extractor.Process(ctx, query, values)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, entryValue, value)
|
||||
|
||||
@@ -69,13 +74,13 @@ func TestJSONProcess(t *testing.T) {
|
||||
values = &[]result.Value{
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: jsonString},
|
||||
}
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err = extractor.Process(ctx, query, values)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, entryValue, value)
|
||||
}
|
||||
@@ -93,8 +98,12 @@ func TestJSONProcessJSON(t *testing.T) {
|
||||
|
||||
extractor := jsonextractor.New(queries)
|
||||
|
||||
queryID := uuid.New()
|
||||
queryVersion := int32(1)
|
||||
query := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: query.TypeJsonExtractor,
|
||||
RequiredQueryID: uuid.Nil,
|
||||
Version: int32(1),
|
||||
}
|
||||
entryValue := "value"
|
||||
|
||||
jsonString := fmt.Sprintf("{\"key\": \"%s\"}", entryValue)
|
||||
@@ -104,48 +113,48 @@ func TestJSONProcessJSON(t *testing.T) {
|
||||
|
||||
config := "{\"path\":\"invalid_key\"}"
|
||||
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err := extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err := extractor.Process(ctx, query, values)
|
||||
assert.EqualError(t, err, "JSON path does not exist: invalid_key")
|
||||
assert.Empty(t, value)
|
||||
|
||||
config = "{\"path\":\"\"}"
|
||||
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err = extractor.Process(ctx, query, values)
|
||||
assert.EqualError(t, err, "JSON path does not exist: ")
|
||||
assert.Empty(t, value)
|
||||
|
||||
config = "{\"path\":}"
|
||||
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}).
|
||||
AddRow(pgtype.UUID{}, []byte(config)),
|
||||
)
|
||||
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err = extractor.Process(ctx, query, values)
|
||||
assert.EqualError(t, err, "invalid character '}' looking for beginning of value")
|
||||
assert.Empty(t, value)
|
||||
|
||||
config = "{\"path\":\"key\"}"
|
||||
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(queryID), queryVersion).
|
||||
db.ExpectQuery("name: GetQueryConfig :one").WithArgs(database.MustToDBUUID(query.ID), query.Version).
|
||||
WillReturnRows(
|
||||
pgxmock.NewRows([]string{"id", "config"}),
|
||||
)
|
||||
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, values)
|
||||
value, err = extractor.Process(ctx, query, values)
|
||||
assert.EqualError(t, err, "no rows in result set")
|
||||
assert.Empty(t, value)
|
||||
}
|
||||
@@ -163,11 +172,15 @@ func TestJSONProcessResults(t *testing.T) {
|
||||
|
||||
extractor := jsonextractor.New(queries)
|
||||
|
||||
queryID := uuid.New()
|
||||
queryVersion := int32(1)
|
||||
query := query.Query{
|
||||
ID: uuid.New(),
|
||||
Type: query.TypeJsonExtractor,
|
||||
RequiredQueryID: uuid.Nil,
|
||||
Version: int32(1),
|
||||
}
|
||||
|
||||
results := &[]result.Value{}
|
||||
value, err := extractor.Process(ctx, queryID, queryVersion, results)
|
||||
value, err := extractor.Process(ctx, query, results)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
assert.Empty(t, value)
|
||||
|
||||
@@ -175,7 +188,7 @@ func TestJSONProcessResults(t *testing.T) {
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
}
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, results)
|
||||
value, err = extractor.Process(ctx, query, results)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
assert.Empty(t, value)
|
||||
|
||||
@@ -184,7 +197,7 @@ func TestJSONProcessResults(t *testing.T) {
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
{ID: uuid.New(), QueryID: uuid.New(), Value: ""},
|
||||
}
|
||||
value, err = extractor.Process(ctx, queryID, queryVersion, results)
|
||||
value, err = extractor.Process(ctx, query, results)
|
||||
assert.EqualError(t, err, "JSON Extraction requires 1 result")
|
||||
assert.Empty(t, value)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseDBQuery(t *testing.T) {
|
||||
dbResult := repository.GetCollectorQueriesRow{
|
||||
Collectorid: pgtype.UUID{},
|
||||
Queryid: pgtype.UUID{},
|
||||
Requiredqueryid: pgtype.UUID{},
|
||||
Type: repository.NullQuerytype{Valid: true, Querytype: repository.QuerytypeJsonExtractor},
|
||||
Queryversion: pgtype.Int4{},
|
||||
}
|
||||
value, err := query.ParseDBQuery(&dbResult)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, uuid.Nil, value.ID)
|
||||
assert.Equal(t, uuid.Nil, value.RequiredQueryID)
|
||||
assert.Equal(t, int32(0), value.Version)
|
||||
assert.Equal(t, query.Type(query.TypeJsonExtractor), value.Type)
|
||||
|
||||
dbResult.Type = repository.NullQuerytype{}
|
||||
_, err = query.ParseDBQuery(&dbResult)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
}
|
||||
|
||||
func TestParseDBType(t *testing.T) {
|
||||
qType := repository.NullQuerytype{Valid: true, Querytype: repository.QuerytypeJsonExtractor}
|
||||
value, err := query.ParseDBType(qType)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, query.Type(query.TypeJsonExtractor), value)
|
||||
|
||||
qType = repository.NullQuerytype{}
|
||||
_, err = query.ParseDBType(qType)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
|
||||
qType = repository.NullQuerytype{Valid: true}
|
||||
_, err = query.ParseDBType(qType)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
}
|
||||
|
||||
func TestToDBQueryType(t *testing.T) {
|
||||
dbQueryType := query.Type(query.TypeJsonExtractor)
|
||||
value, err := query.ToDBQueryType(dbQueryType)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, repository.NullQuerytype{Querytype: repository.QuerytypeJsonExtractor, Valid: true}, value)
|
||||
|
||||
dbQueryType = query.Type(-1)
|
||||
_, err = query.ToDBQueryType(dbQueryType)
|
||||
assert.EqualError(t, err, "invalid database query type")
|
||||
}
|
||||
+19
-15
@@ -6,6 +6,8 @@ import (
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/query"
|
||||
"gotemplate/internal/queryQueue"
|
||||
"gotemplate/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -51,44 +53,46 @@ func TestQueue(t *testing.T) {
|
||||
querySixID := uuid.New()
|
||||
querySixVersion := int32(6)
|
||||
collectorQueries := []query.Query{
|
||||
{ID: queryOneID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
{ID: queryTwoID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryThreeID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryThreeVersion},
|
||||
{ID: queryThreeID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryFourID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryFourVersion},
|
||||
{ID: queryFiveID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: querySixID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
{ID: queryTwoID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryThreeVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryFourID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryFourVersion},
|
||||
{ID: queryFiveID, Type: query.TypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
}
|
||||
|
||||
rows := pgxmock.NewRows([]string{"collectorId", "queryId", "type", "requiredQueryId", "queryVersion"})
|
||||
for _, q := range collectorQueries {
|
||||
dbID := database.MustToDBUUID(q.ID)
|
||||
dbReqID := database.MustToDBUUID(q.RequiredQueryID)
|
||||
ty, err := query.ToDBQueryType(q.Type)
|
||||
assert.Nil(t, err)
|
||||
rows = rows.
|
||||
AddRow(dbCollectorID, dbID, query.ToDBQueryType(q.Type), dbReqID, pgtype.Int4{Int32: int32(q.Version), Valid: true})
|
||||
AddRow(dbCollectorID, dbID, ty, dbReqID, pgtype.Int4{Int32: int32(q.Version), Valid: true})
|
||||
}
|
||||
|
||||
db.ExpectQuery("name: GetCollectorQueries :many").WithArgs(dbCollectorID).WillReturnRows(rows)
|
||||
|
||||
results := []query.Result{
|
||||
results := []result.Result{
|
||||
{ID: uuid.New(), QueryID: queryFourID, QueryVersion: queryFourVersion},
|
||||
{ID: uuid.New(), QueryID: querySixID, QueryVersion: querySixVersion - 1},
|
||||
{ID: uuid.New(), QueryID: queryOneID, QueryVersion: queryOneVersion - 1},
|
||||
}
|
||||
|
||||
expectedQueries := []query.Query{
|
||||
{ID: querySixID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
{ID: queryFiveID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: queryThreeID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryTwoID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryOneID, Type: query.QueryTypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
{ID: querySixID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: querySixVersion},
|
||||
{ID: queryFiveID, Type: query.TypeJsonExtractor, RequiredQueryID: querySixID, Version: queryFiveVersion},
|
||||
{ID: queryThreeID, Type: query.TypeJsonExtractor, RequiredQueryID: queryTwoID, Version: queryThreeVersion},
|
||||
{ID: queryTwoID, Type: query.TypeJsonExtractor, RequiredQueryID: queryOneID, Version: queryTwoVersion},
|
||||
{ID: queryOneID, Type: query.TypeJsonExtractor, RequiredQueryID: uuid.Nil, Version: queryOneVersion},
|
||||
}
|
||||
|
||||
docID := uuid.New()
|
||||
cleanVersion := int32(1)
|
||||
textVersion := int32(1)
|
||||
|
||||
q, err := query.NewQueue(ctx, queries, coll, &results, docID, cleanVersion, textVersion)
|
||||
q, err := queryQueue.New(ctx, queries, coll, &results, docID, cleanVersion, textVersion)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, expectedQueries, q.GetQueue())
|
||||
|
||||
@@ -10,15 +10,28 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseResultValue(t *testing.T) {
|
||||
func TestParseValue(t *testing.T) {
|
||||
dbResult := repository.ListResultValuesByIDRow{
|
||||
ID: pgtype.UUID{},
|
||||
Queryid: pgtype.UUID{},
|
||||
Value: "",
|
||||
}
|
||||
|
||||
value := result.ParseResultValue(dbResult)
|
||||
value := result.ParseValue(&dbResult)
|
||||
assert.Equal(t, dbResult.Value, value.Value)
|
||||
assert.Equal(t, uuid.Nil, value.ID)
|
||||
assert.Equal(t, uuid.Nil, value.QueryID)
|
||||
}
|
||||
|
||||
func TestParseResultValue(t *testing.T) {
|
||||
dbResult := repository.ListResultsByDocumentIDRow{
|
||||
ID: pgtype.UUID{},
|
||||
Queryid: pgtype.UUID{},
|
||||
Queryversion: int32(1),
|
||||
}
|
||||
|
||||
value := result.Parse(&dbResult)
|
||||
assert.Equal(t, dbResult.Queryversion, value.QueryVersion)
|
||||
assert.Equal(t, uuid.Nil, value.ID)
|
||||
assert.Equal(t, uuid.Nil, value.QueryID)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package document_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"gotemplate/internal/database"
|
||||
"gotemplate/internal/database/repository"
|
||||
"gotemplate/internal/result"
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/pashagolub/pgxmock/v3"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db, err := pgxmock.NewConn()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open pgxmock database: %v", err)
|
||||
}
|
||||
defer db.Close(ctx)
|
||||
|
||||
queries := repository.New(db)
|
||||
|
||||
resultStore := result.ResultStore{
|
||||
QueryID: uuid.New(),
|
||||
DocumentID: uuid.New(),
|
||||
Value: "val",
|
||||
CleanVersion: int32(1),
|
||||
TextVersion: int32(1),
|
||||
QueryVersion: int32(1),
|
||||
}
|
||||
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnResult(pgxmock.NewResult("", 1))
|
||||
|
||||
id, err := result.Store(ctx, queries, &resultStore)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, id)
|
||||
|
||||
errr := "database failing"
|
||||
db.ExpectExec("name: SetResult :exec").WithArgs(pgxmock.AnyArg(), database.MustToDBUUID(resultStore.QueryID), database.MustToDBUUID(resultStore.DocumentID), resultStore.Value, resultStore.CleanVersion, resultStore.TextVersion, resultStore.QueryVersion).
|
||||
WillReturnError(fmt.Errorf(errr))
|
||||
|
||||
id, err = result.Store(ctx, queries, &resultStore)
|
||||
assert.EqualError(t, err, errr)
|
||||
assert.Equal(t, uuid.Nil, id)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package winterm
|
||||
|
||||
+20
-19
@@ -15,26 +15,26 @@ import (
|
||||
// When defining struct types. the `document` struct tag can be used to control how the value will be
|
||||
// marshaled into the resulting protocol document.
|
||||
//
|
||||
// // Field is ignored
|
||||
// Field int `document:"-"`
|
||||
// // Field is ignored
|
||||
// Field int `document:"-"`
|
||||
//
|
||||
// // Field object of key "myName"
|
||||
// Field int `document:"myName"`
|
||||
// // Field object of key "myName"
|
||||
// Field int `document:"myName"`
|
||||
//
|
||||
// // Field object key of key "myName", and
|
||||
// // Field is omitted if the field is a zero value for the type.
|
||||
// Field int `document:"myName,omitempty"`
|
||||
// // Field object key of key "myName", and
|
||||
// // Field is omitted if the field is a zero value for the type.
|
||||
// Field int `document:"myName,omitempty"`
|
||||
//
|
||||
// // Field object key of "Field", and
|
||||
// // Field is omitted if the field is a zero value for the type.
|
||||
// Field int `document:",omitempty"`
|
||||
// // Field object key of "Field", and
|
||||
// // Field is omitted if the field is a zero value for the type.
|
||||
// Field int `document:",omitempty"`
|
||||
//
|
||||
// All struct fields, including anonymous fields, are marshaled unless the
|
||||
// any of the following conditions are meet.
|
||||
//
|
||||
// - the field is not exported
|
||||
// - document field tag is "-"
|
||||
// - document field tag specifies "omitempty", and is a zero value.
|
||||
// - the field is not exported
|
||||
// - document field tag is "-"
|
||||
// - document field tag specifies "omitempty", and is a zero value.
|
||||
//
|
||||
// Pointer and interface values are encoded as the value pointed to or
|
||||
// contained in the interface. A nil value encodes as a null
|
||||
@@ -63,12 +63,13 @@ type Marshaler interface {
|
||||
//
|
||||
// Both generic interface{} and concrete types are valid unmarshal destination types. When unmarshaling a document
|
||||
// into an empty interface the Unmarshaler will store one of these values:
|
||||
// bool, for boolean values
|
||||
// document.Number, for arbitrary-precision numbers (int64, float64, big.Int, big.Float)
|
||||
// string, for string values
|
||||
// []interface{}, for array values
|
||||
// map[string]interface{}, for objects
|
||||
// nil, for null values
|
||||
//
|
||||
// bool, for boolean values
|
||||
// document.Number, for arbitrary-precision numbers (int64, float64, big.Int, big.Float)
|
||||
// string, for string values
|
||||
// []interface{}, for array values
|
||||
// map[string]interface{}, for objects
|
||||
// nil, for null values
|
||||
//
|
||||
// When unmarshaling, any error that occurs will halt the unmarshal and return the error.
|
||||
type Unmarshaler interface {
|
||||
|
||||
+5
-5
@@ -4,21 +4,21 @@ shape serializer function in which a xml.Value will be passed around.
|
||||
|
||||
Resources followed: https://smithy.io/2.0/spec/protocol-traits.html#xml-bindings
|
||||
|
||||
Member Element
|
||||
# Member Element
|
||||
|
||||
Member element should be used to encode xml shapes into xml elements except for flattened xml shapes. Member element
|
||||
write their own element start tag. These elements should always be closed.
|
||||
|
||||
Flattened Element
|
||||
# Flattened Element
|
||||
|
||||
Flattened element should be used to encode shapes marked with flattened trait into xml elements. Flattened element
|
||||
do not write a start tag, and thus should not be closed.
|
||||
|
||||
Simple types encoding
|
||||
# Simple types encoding
|
||||
|
||||
All simple type methods on value such as String(), Long() etc; auto close the associated member element.
|
||||
|
||||
Array
|
||||
# Array
|
||||
|
||||
Array returns the collection encoder. It has two modes, wrapped and flattened encoding.
|
||||
|
||||
@@ -32,7 +32,7 @@ If a shape is marked as flattened, Array() will use the shape element name as wr
|
||||
|
||||
<flattenedAarray>apple</flattenedArray><flattenedArray>tree</flattenedArray>
|
||||
|
||||
Map
|
||||
# Map
|
||||
|
||||
Map is the map encoder. It has two modes, wrapped and flattened encoding.
|
||||
|
||||
|
||||
+10
-10
@@ -14,7 +14,7 @@
|
||||
// handler. A handler could be something like an HTTP Client that round trips an
|
||||
// API operation over HTTP.
|
||||
//
|
||||
// Smithy Middleware Stack
|
||||
// # Smithy Middleware Stack
|
||||
//
|
||||
// A Stack is a collection of middleware that wrap a handler. The stack can be
|
||||
// broken down into discreet steps. Each step may contain zero or more middleware
|
||||
@@ -48,20 +48,20 @@
|
||||
// the request message. Deserializes the response into a structured type or
|
||||
// error above stacks can react to.
|
||||
//
|
||||
// Adding Middleware to a Stack Step
|
||||
// # Adding Middleware to a Stack Step
|
||||
//
|
||||
// Middleware can be added to a step front or back, or relative, by name, to an
|
||||
// existing middleware in that stack. If a middleware does not have a name, a
|
||||
// unique name will be generated at the middleware and be added to the step.
|
||||
//
|
||||
// // Create middleware stack
|
||||
// stack := middleware.NewStack()
|
||||
// // Create middleware stack
|
||||
// stack := middleware.NewStack()
|
||||
//
|
||||
// // Add middleware to stack steps
|
||||
// stack.Initialize.Add(paramValidationMiddleware, middleware.After)
|
||||
// stack.Serialize.Add(marshalOperationFoo, middleware.After)
|
||||
// stack.Deserialize.Add(unmarshalOperationFoo, middleware.After)
|
||||
// // Add middleware to stack steps
|
||||
// stack.Initialize.Add(paramValidationMiddleware, middleware.After)
|
||||
// stack.Serialize.Add(marshalOperationFoo, middleware.After)
|
||||
// stack.Deserialize.Add(unmarshalOperationFoo, middleware.After)
|
||||
//
|
||||
// // Invoke middleware on handler.
|
||||
// resp, err := stack.HandleMiddleware(ctx, req.Input, clientHandler)
|
||||
// // Invoke middleware on handler.
|
||||
// resp, err := stack.HandleMiddleware(ctx, req.Input, clientHandler)
|
||||
package middleware
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import (
|
||||
// Steps are composed as middleware around the underlying handler in the
|
||||
// following order:
|
||||
//
|
||||
// Initialize -> Serialize -> Build -> Finalize -> Deserialize -> Handler
|
||||
// Initialize -> Serialize -> Build -> Finalize -> Deserialize -> Handler
|
||||
//
|
||||
// Any middleware within the chain may choose to stop and return an error or
|
||||
// response. Since the middleware decorate the handler like a call stack, each
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
// Middleware that does not need to react to an input, or result must forward
|
||||
// along the input down the chain, or return the result back up the chain.
|
||||
//
|
||||
// Initialize <- Serialize -> Build -> Finalize <- Deserialize <- Handler
|
||||
// Initialize <- Serialize -> Build -> Finalize <- Deserialize <- Handler
|
||||
type Stack struct {
|
||||
// Initialize prepares the input, and sets any default parameters as
|
||||
// needed, (e.g. idempotency token, and presigned URLs).
|
||||
|
||||
+20
-18
@@ -11,17 +11,17 @@ period for each retry attempt using a randomization function that grows exponent
|
||||
|
||||
NextBackOff() is calculated using the following formula:
|
||||
|
||||
randomized interval =
|
||||
RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])
|
||||
randomized interval =
|
||||
RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])
|
||||
|
||||
In other words NextBackOff() will range between the randomization factor
|
||||
percentage below and above the retry interval.
|
||||
|
||||
For example, given the following parameters:
|
||||
|
||||
RetryInterval = 2
|
||||
RandomizationFactor = 0.5
|
||||
Multiplier = 2
|
||||
RetryInterval = 2
|
||||
RandomizationFactor = 0.5
|
||||
Multiplier = 2
|
||||
|
||||
the actual backoff period used in the next retry attempt will range between 1 and 3 seconds,
|
||||
multiplied by the exponential, that is, between 2 and 6 seconds.
|
||||
@@ -36,18 +36,18 @@ The elapsed time can be reset by calling Reset().
|
||||
Example: Given the following default arguments, for 10 tries the sequence will be,
|
||||
and assuming we go over the MaxElapsedTime on the 10th try:
|
||||
|
||||
Request # RetryInterval (seconds) Randomized Interval (seconds)
|
||||
Request # RetryInterval (seconds) Randomized Interval (seconds)
|
||||
|
||||
1 0.5 [0.25, 0.75]
|
||||
2 0.75 [0.375, 1.125]
|
||||
3 1.125 [0.562, 1.687]
|
||||
4 1.687 [0.8435, 2.53]
|
||||
5 2.53 [1.265, 3.795]
|
||||
6 3.795 [1.897, 5.692]
|
||||
7 5.692 [2.846, 8.538]
|
||||
8 8.538 [4.269, 12.807]
|
||||
9 12.807 [6.403, 19.210]
|
||||
10 19.210 backoff.Stop
|
||||
1 0.5 [0.25, 0.75]
|
||||
2 0.75 [0.375, 1.125]
|
||||
3 1.125 [0.562, 1.687]
|
||||
4 1.687 [0.8435, 2.53]
|
||||
5 2.53 [1.265, 3.795]
|
||||
6 3.795 [1.897, 5.692]
|
||||
7 5.692 [2.846, 8.538]
|
||||
8 8.538 [4.269, 12.807]
|
||||
9 12.807 [6.403, 19.210]
|
||||
10 19.210 backoff.Stop
|
||||
|
||||
Note: Implementation is not thread-safe.
|
||||
*/
|
||||
@@ -167,7 +167,8 @@ func (b *ExponentialBackOff) Reset() {
|
||||
}
|
||||
|
||||
// NextBackOff calculates the next backoff interval using the formula:
|
||||
// Randomized interval = RetryInterval * (1 ± RandomizationFactor)
|
||||
//
|
||||
// Randomized interval = RetryInterval * (1 ± RandomizationFactor)
|
||||
func (b *ExponentialBackOff) NextBackOff() time.Duration {
|
||||
// Make sure we have not gone over the maximum elapsed time.
|
||||
elapsed := b.GetElapsedTime()
|
||||
@@ -200,7 +201,8 @@ func (b *ExponentialBackOff) incrementCurrentInterval() {
|
||||
}
|
||||
|
||||
// Returns a random value from the following interval:
|
||||
// [currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval].
|
||||
//
|
||||
// [currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval].
|
||||
func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration {
|
||||
if randomizationFactor == 0 {
|
||||
return currentInterval // make sure no randomness is used when randomizationFactor is 0.
|
||||
|
||||
+1
@@ -18,6 +18,7 @@
|
||||
// tag is deprecated and thus should not be used.
|
||||
// Go versions prior to 1.4 are disabled because they use a different layout
|
||||
// for interfaces which make the implementation of unsafeReflectValue more complex.
|
||||
//go:build !js && !appengine && !safe && !disableunsafe && go1.4
|
||||
// +build !js,!appengine,!safe,!disableunsafe,go1.4
|
||||
|
||||
package spew
|
||||
|
||||
+1
@@ -16,6 +16,7 @@
|
||||
// when the code is running on Google App Engine, compiled by GopherJS, or
|
||||
// "-tags safe" is added to the go build command line. The "disableunsafe"
|
||||
// tag is deprecated and thus should not be used.
|
||||
//go:build js || appengine || safe || disableunsafe || !go1.4
|
||||
// +build js appengine safe disableunsafe !go1.4
|
||||
|
||||
package spew
|
||||
|
||||
+15
-15
@@ -254,15 +254,15 @@ pointer addresses used to indirect to the final value. It provides the
|
||||
following features over the built-in printing facilities provided by the fmt
|
||||
package:
|
||||
|
||||
* Pointers are dereferenced and followed
|
||||
* Circular data structures are detected and handled properly
|
||||
* Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
* Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output
|
||||
- Pointers are dereferenced and followed
|
||||
- Circular data structures are detected and handled properly
|
||||
- Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
- Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
- Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output
|
||||
|
||||
The configuration options are controlled by modifying the public members
|
||||
of c. See ConfigState for options documentation.
|
||||
@@ -295,12 +295,12 @@ func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{})
|
||||
|
||||
// NewDefaultConfig returns a ConfigState with the following default settings.
|
||||
//
|
||||
// Indent: " "
|
||||
// MaxDepth: 0
|
||||
// DisableMethods: false
|
||||
// DisablePointerMethods: false
|
||||
// ContinueOnMethod: false
|
||||
// SortKeys: false
|
||||
// Indent: " "
|
||||
// MaxDepth: 0
|
||||
// DisableMethods: false
|
||||
// DisablePointerMethods: false
|
||||
// ContinueOnMethod: false
|
||||
// SortKeys: false
|
||||
func NewDefaultConfig() *ConfigState {
|
||||
return &ConfigState{Indent: " "}
|
||||
}
|
||||
|
||||
+67
-61
@@ -21,35 +21,36 @@ debugging.
|
||||
A quick overview of the additional features spew provides over the built-in
|
||||
printing facilities for Go data types are as follows:
|
||||
|
||||
* Pointers are dereferenced and followed
|
||||
* Circular data structures are detected and handled properly
|
||||
* Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
* Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output (only when using
|
||||
Dump style)
|
||||
- Pointers are dereferenced and followed
|
||||
- Circular data structures are detected and handled properly
|
||||
- Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
- Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
- Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output (only when using
|
||||
Dump style)
|
||||
|
||||
There are two different approaches spew allows for dumping Go data structures:
|
||||
|
||||
* Dump style which prints with newlines, customizable indentation,
|
||||
and additional debug information such as types and all pointer addresses
|
||||
used to indirect to the final value
|
||||
* A custom Formatter interface that integrates cleanly with the standard fmt
|
||||
package and replaces %v, %+v, %#v, and %#+v to provide inline printing
|
||||
similar to the default %v while providing the additional functionality
|
||||
outlined above and passing unsupported format verbs such as %x and %q
|
||||
along to fmt
|
||||
- Dump style which prints with newlines, customizable indentation,
|
||||
and additional debug information such as types and all pointer addresses
|
||||
used to indirect to the final value
|
||||
- A custom Formatter interface that integrates cleanly with the standard fmt
|
||||
package and replaces %v, %+v, %#v, and %#+v to provide inline printing
|
||||
similar to the default %v while providing the additional functionality
|
||||
outlined above and passing unsupported format verbs such as %x and %q
|
||||
along to fmt
|
||||
|
||||
Quick Start
|
||||
# Quick Start
|
||||
|
||||
This section demonstrates how to quickly get started with spew. See the
|
||||
sections below for further details on formatting and configuration options.
|
||||
|
||||
To dump a variable with full newlines, indentation, type, and pointer
|
||||
information use Dump, Fdump, or Sdump:
|
||||
|
||||
spew.Dump(myVar1, myVar2, ...)
|
||||
spew.Fdump(someWriter, myVar1, myVar2, ...)
|
||||
str := spew.Sdump(myVar1, myVar2, ...)
|
||||
@@ -58,12 +59,13 @@ Alternatively, if you would prefer to use format strings with a compacted inline
|
||||
printing style, use the convenience wrappers Printf, Fprintf, etc with
|
||||
%v (most compact), %+v (adds pointer addresses), %#v (adds types), or
|
||||
%#+v (adds types and pointer addresses):
|
||||
|
||||
spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||
spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||
spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2)
|
||||
spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4)
|
||||
|
||||
Configuration Options
|
||||
# Configuration Options
|
||||
|
||||
Configuration of spew is handled by fields in the ConfigState type. For
|
||||
convenience, all of the top-level functions use a global state available
|
||||
@@ -74,51 +76,52 @@ equivalent to the top-level functions. This allows concurrent configuration
|
||||
options. See the ConfigState documentation for more details.
|
||||
|
||||
The following configuration options are available:
|
||||
* Indent
|
||||
String to use for each indentation level for Dump functions.
|
||||
It is a single space by default. A popular alternative is "\t".
|
||||
|
||||
* MaxDepth
|
||||
Maximum number of levels to descend into nested data structures.
|
||||
There is no limit by default.
|
||||
- Indent
|
||||
String to use for each indentation level for Dump functions.
|
||||
It is a single space by default. A popular alternative is "\t".
|
||||
|
||||
* DisableMethods
|
||||
Disables invocation of error and Stringer interface methods.
|
||||
Method invocation is enabled by default.
|
||||
- MaxDepth
|
||||
Maximum number of levels to descend into nested data structures.
|
||||
There is no limit by default.
|
||||
|
||||
* DisablePointerMethods
|
||||
Disables invocation of error and Stringer interface methods on types
|
||||
which only accept pointer receivers from non-pointer variables.
|
||||
Pointer method invocation is enabled by default.
|
||||
- DisableMethods
|
||||
Disables invocation of error and Stringer interface methods.
|
||||
Method invocation is enabled by default.
|
||||
|
||||
* DisablePointerAddresses
|
||||
DisablePointerAddresses specifies whether to disable the printing of
|
||||
pointer addresses. This is useful when diffing data structures in tests.
|
||||
- DisablePointerMethods
|
||||
Disables invocation of error and Stringer interface methods on types
|
||||
which only accept pointer receivers from non-pointer variables.
|
||||
Pointer method invocation is enabled by default.
|
||||
|
||||
* DisableCapacities
|
||||
DisableCapacities specifies whether to disable the printing of
|
||||
capacities for arrays, slices, maps and channels. This is useful when
|
||||
diffing data structures in tests.
|
||||
- DisablePointerAddresses
|
||||
DisablePointerAddresses specifies whether to disable the printing of
|
||||
pointer addresses. This is useful when diffing data structures in tests.
|
||||
|
||||
* ContinueOnMethod
|
||||
Enables recursion into types after invoking error and Stringer interface
|
||||
methods. Recursion after method invocation is disabled by default.
|
||||
- DisableCapacities
|
||||
DisableCapacities specifies whether to disable the printing of
|
||||
capacities for arrays, slices, maps and channels. This is useful when
|
||||
diffing data structures in tests.
|
||||
|
||||
* SortKeys
|
||||
Specifies map keys should be sorted before being printed. Use
|
||||
this to have a more deterministic, diffable output. Note that
|
||||
only native types (bool, int, uint, floats, uintptr and string)
|
||||
and types which implement error or Stringer interfaces are
|
||||
supported with other types sorted according to the
|
||||
reflect.Value.String() output which guarantees display
|
||||
stability. Natural map order is used by default.
|
||||
- ContinueOnMethod
|
||||
Enables recursion into types after invoking error and Stringer interface
|
||||
methods. Recursion after method invocation is disabled by default.
|
||||
|
||||
* SpewKeys
|
||||
Specifies that, as a last resort attempt, map keys should be
|
||||
spewed to strings and sorted by those strings. This is only
|
||||
considered if SortKeys is true.
|
||||
- SortKeys
|
||||
Specifies map keys should be sorted before being printed. Use
|
||||
this to have a more deterministic, diffable output. Note that
|
||||
only native types (bool, int, uint, floats, uintptr and string)
|
||||
and types which implement error or Stringer interfaces are
|
||||
supported with other types sorted according to the
|
||||
reflect.Value.String() output which guarantees display
|
||||
stability. Natural map order is used by default.
|
||||
|
||||
Dump Usage
|
||||
- SpewKeys
|
||||
Specifies that, as a last resort attempt, map keys should be
|
||||
spewed to strings and sorted by those strings. This is only
|
||||
considered if SortKeys is true.
|
||||
|
||||
# Dump Usage
|
||||
|
||||
Simply call spew.Dump with a list of variables you want to dump:
|
||||
|
||||
@@ -133,7 +136,7 @@ A third option is to call spew.Sdump to get the formatted output as a string:
|
||||
|
||||
str := spew.Sdump(myVar1, myVar2, ...)
|
||||
|
||||
Sample Dump Output
|
||||
# Sample Dump Output
|
||||
|
||||
See the Dump example for details on the setup of the types and variables being
|
||||
shown here.
|
||||
@@ -150,13 +153,14 @@ shown here.
|
||||
|
||||
Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C
|
||||
command as shown.
|
||||
|
||||
([]uint8) (len=32 cap=32) {
|
||||
00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... |
|
||||
00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0|
|
||||
00000020 31 32 |12|
|
||||
}
|
||||
|
||||
Custom Formatter
|
||||
# Custom Formatter
|
||||
|
||||
Spew provides a custom formatter that implements the fmt.Formatter interface
|
||||
so that it integrates cleanly with standard fmt package printing functions. The
|
||||
@@ -170,7 +174,7 @@ standard fmt package for formatting. In addition, the custom formatter ignores
|
||||
the width and precision arguments (however they will still work on the format
|
||||
specifiers not handled by the custom formatter).
|
||||
|
||||
Custom Formatter Usage
|
||||
# Custom Formatter Usage
|
||||
|
||||
The simplest way to make use of the spew custom formatter is to call one of the
|
||||
convenience functions such as spew.Printf, spew.Println, or spew.Printf. The
|
||||
@@ -184,15 +188,17 @@ functions have syntax you are most likely already familiar with:
|
||||
|
||||
See the Index for the full list convenience functions.
|
||||
|
||||
Sample Formatter Output
|
||||
# Sample Formatter Output
|
||||
|
||||
Double pointer to a uint8:
|
||||
|
||||
%v: <**>5
|
||||
%+v: <**>(0xf8400420d0->0xf8400420c8)5
|
||||
%#v: (**uint8)5
|
||||
%#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5
|
||||
|
||||
Pointer to circular struct with a uint8 field and a pointer to itself:
|
||||
|
||||
%v: <*>{1 <*><shown>}
|
||||
%+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)<shown>}
|
||||
%#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)<shown>}
|
||||
@@ -201,7 +207,7 @@ Pointer to circular struct with a uint8 field and a pointer to itself:
|
||||
See the Printf example for details on the setup of variables being shown
|
||||
here.
|
||||
|
||||
Errors
|
||||
# Errors
|
||||
|
||||
Since it is possible for custom Stringer/error interfaces to panic, spew
|
||||
detects them and handles them internally by printing the panic information
|
||||
|
||||
+9
-9
@@ -488,15 +488,15 @@ pointer addresses used to indirect to the final value. It provides the
|
||||
following features over the built-in printing facilities provided by the fmt
|
||||
package:
|
||||
|
||||
* Pointers are dereferenced and followed
|
||||
* Circular data structures are detected and handled properly
|
||||
* Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
* Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
* Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output
|
||||
- Pointers are dereferenced and followed
|
||||
- Circular data structures are detected and handled properly
|
||||
- Custom Stringer/error interfaces are optionally invoked, including
|
||||
on unexported types
|
||||
- Custom types which only implement the Stringer/error interfaces via
|
||||
a pointer receiver are optionally invoked when passing non-pointer
|
||||
variables
|
||||
- Byte arrays and slices are dumped like the hexdump -C command which
|
||||
includes offsets, byte values in hex, and ASCII output
|
||||
|
||||
The configuration options are controlled by an exported package global,
|
||||
spew.Config. See ConfigState for options documentation.
|
||||
|
||||
+2
@@ -1,4 +1,6 @@
|
||||
//go:build go1.8
|
||||
// +build go1.8
|
||||
|
||||
// Code generated by "httpsnoop/codegen"; DO NOT EDIT.
|
||||
|
||||
package httpsnoop
|
||||
|
||||
+2
@@ -1,4 +1,6 @@
|
||||
//go:build !go1.8
|
||||
// +build !go1.8
|
||||
|
||||
// Code generated by "httpsnoop/codegen"; DO NOT EDIT.
|
||||
|
||||
package httpsnoop
|
||||
|
||||
+14
-13
@@ -154,11 +154,11 @@ func Marc(raw []byte, limit uint32) bool {
|
||||
// the GL transmission Format (glTF).
|
||||
// GLB uses little endian and its header structure is as follows:
|
||||
//
|
||||
// <-- 12-byte header -->
|
||||
// | magic | version | length |
|
||||
// | (uint32) | (uint32) | (uint32) |
|
||||
// | \x67\x6C\x54\x46 | \x01\x00\x00\x00 | ... |
|
||||
// | g l T F | 1 | ... |
|
||||
// <-- 12-byte header -->
|
||||
// | magic | version | length |
|
||||
// | (uint32) | (uint32) | (uint32) |
|
||||
// | \x67\x6C\x54\x46 | \x01\x00\x00\x00 | ... |
|
||||
// | g l T F | 1 | ... |
|
||||
//
|
||||
// Visit [glTF specification] and [IANA glTF entry] for more details.
|
||||
//
|
||||
@@ -170,14 +170,15 @@ var Glb = prefix([]byte("\x67\x6C\x54\x46\x02\x00\x00\x00"),
|
||||
// TzIf matches a Time Zone Information Format (TZif) file.
|
||||
// See more: https://tools.ietf.org/id/draft-murchison-tzdist-tzif-00.html#rfc.section.3
|
||||
// Its header structure is shown below:
|
||||
// +---------------+---+
|
||||
// | magic (4) | <-+-- version (1)
|
||||
// +---------------+---+---------------------------------------+
|
||||
// | [unused - reserved for future use] (15) |
|
||||
// +---------------+---------------+---------------+-----------+
|
||||
// | isutccnt (4) | isstdcnt (4) | leapcnt (4) |
|
||||
// +---------------+---------------+---------------+
|
||||
// | timecnt (4) | typecnt (4) | charcnt (4) |
|
||||
//
|
||||
// +---------------+---+
|
||||
// | magic (4) | <-+-- version (1)
|
||||
// +---------------+---+---------------------------------------+
|
||||
// | [unused - reserved for future use] (15) |
|
||||
// +---------------+---------------+---------------+-----------+
|
||||
// | isutccnt (4) | isstdcnt (4) | leapcnt (4) |
|
||||
// +---------------+---------------+---------------+
|
||||
// | timecnt (4) | typecnt (4) | charcnt (4) |
|
||||
func TzIf(raw []byte, limit uint32) bool {
|
||||
// File is at least 44 bytes (header size).
|
||||
if len(raw) < 44 {
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+5
-5
@@ -108,9 +108,9 @@ type GUID struct {
|
||||
//
|
||||
// The supplied string may be in any of these formats:
|
||||
//
|
||||
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
|
||||
// XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
//
|
||||
// The conversion of the supplied string is not case-sensitive.
|
||||
func NewGUID(guid string) *GUID {
|
||||
@@ -216,11 +216,11 @@ func decodeHexChar(c byte) (byte, bool) {
|
||||
|
||||
// String converts the GUID to string form. It will adhere to this pattern:
|
||||
//
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
// {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
|
||||
//
|
||||
// If the GUID is nil, the string representation of an empty GUID is returned:
|
||||
//
|
||||
// {00000000-0000-0000-0000-000000000000}
|
||||
// {00000000-0000-0000-0000-000000000000}
|
||||
func (guid *GUID) String() string {
|
||||
if guid == nil {
|
||||
return emptyGUID
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package oleutil
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package oleutil
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
// This file is here so go get succeeds as without it errors with:
|
||||
// no buildable Go source files in ...
|
||||
//
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package oleutil
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
-1
@@ -84,7 +84,7 @@ func (sac *SafeArrayConversion) ToValueArray() (values []interface{}) {
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_BSTR:
|
||||
v , _ := safeArrayGetElementString(sac.Array, i)
|
||||
v, _ := safeArrayGetElementString(sac.Array, i)
|
||||
values[i] = v
|
||||
case VT_VARIANT:
|
||||
var v VARIANT
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build 386
|
||||
// +build 386
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build amd64
|
||||
// +build amd64
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build arm
|
||||
// +build arm
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows && 386
|
||||
// +build windows,386
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows && amd64
|
||||
// +build windows,amd64
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows && arm
|
||||
// +build windows,arm
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build ppc64le
|
||||
// +build ppc64le
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build s390x
|
||||
// +build s390x
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package ole
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package ole
|
||||
|
||||
+18
-18
@@ -39,35 +39,35 @@ for a protocol buffer variable v:
|
||||
|
||||
- Names are turned from camel_case to CamelCase for export.
|
||||
- There are no methods on v to set fields; just treat
|
||||
them as structure fields.
|
||||
them as structure fields.
|
||||
- There are getters that return a field's value if set,
|
||||
and return the field's default value if unset.
|
||||
The getters work even if the receiver is a nil message.
|
||||
and return the field's default value if unset.
|
||||
The getters work even if the receiver is a nil message.
|
||||
- The zero value for a struct is its correct initialization state.
|
||||
All desired fields must be set before marshaling.
|
||||
All desired fields must be set before marshaling.
|
||||
- A Reset() method will restore a protobuf struct to its zero state.
|
||||
- Non-repeated fields are pointers to the values; nil means unset.
|
||||
That is, optional or required field int32 f becomes F *int32.
|
||||
That is, optional or required field int32 f becomes F *int32.
|
||||
- Repeated fields are slices.
|
||||
- Helper functions are available to aid the setting of fields.
|
||||
msg.Foo = proto.String("hello") // set field
|
||||
msg.Foo = proto.String("hello") // set field
|
||||
- Constants are defined to hold the default values of all fields that
|
||||
have them. They have the form Default_StructName_FieldName.
|
||||
Because the getter methods handle defaulted values,
|
||||
direct use of these constants should be rare.
|
||||
have them. They have the form Default_StructName_FieldName.
|
||||
Because the getter methods handle defaulted values,
|
||||
direct use of these constants should be rare.
|
||||
- Enums are given type names and maps from names to values.
|
||||
Enum values are prefixed by the enclosing message's name, or by the
|
||||
enum's type name if it is a top-level enum. Enum types have a String
|
||||
method, and a Enum method to assist in message construction.
|
||||
Enum values are prefixed by the enclosing message's name, or by the
|
||||
enum's type name if it is a top-level enum. Enum types have a String
|
||||
method, and a Enum method to assist in message construction.
|
||||
- Nested messages, groups and enums have type names prefixed with the name of
|
||||
the surrounding message type.
|
||||
the surrounding message type.
|
||||
- Extensions are given descriptor names that start with E_,
|
||||
followed by an underscore-delimited list of the nested messages
|
||||
that contain it (if any) followed by the CamelCased name of the
|
||||
extension field itself. HasExtension, ClearExtension, GetExtension
|
||||
and SetExtension are functions for manipulating extensions.
|
||||
followed by an underscore-delimited list of the nested messages
|
||||
that contain it (if any) followed by the CamelCased name of the
|
||||
extension field itself. HasExtension, ClearExtension, GetExtension
|
||||
and SetExtension are functions for manipulating extensions.
|
||||
- Oneof field sets are given a single field in their message,
|
||||
with distinguished wrapper types for each possible field value.
|
||||
with distinguished wrapper types for each possible field value.
|
||||
- Marshal and Unmarshal are functions to encode and decode the wire format.
|
||||
|
||||
When the .proto file specifies `syntax="proto3"`, there are some differences:
|
||||
|
||||
+1
@@ -29,6 +29,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//go:build purego || appengine || js
|
||||
// +build purego appengine js
|
||||
|
||||
// This file contains an implementation of proto field accesses using package reflect.
|
||||
|
||||
+1
@@ -26,6 +26,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//go:build purego || appengine || js
|
||||
// +build purego appengine js
|
||||
|
||||
// This file contains an implementation of proto field accesses using package reflect.
|
||||
|
||||
+1
@@ -29,6 +29,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//go:build !purego && !appengine && !js
|
||||
// +build !purego,!appengine,!js
|
||||
|
||||
// This file contains the implementation of the proto field accesses using package unsafe.
|
||||
|
||||
+1
@@ -26,6 +26,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//go:build !purego && !appengine && !js
|
||||
// +build !purego,!appengine,!js
|
||||
|
||||
// This file contains the implementation of the proto field accesses using package unsafe.
|
||||
|
||||
+8
-6
@@ -2004,12 +2004,14 @@ func makeUnmarshalMap(f *reflect.StructField) unmarshaler {
|
||||
|
||||
// makeUnmarshalOneof makes an unmarshaler for oneof fields.
|
||||
// for:
|
||||
// message Msg {
|
||||
// oneof F {
|
||||
// int64 X = 1;
|
||||
// float64 Y = 2;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// message Msg {
|
||||
// oneof F {
|
||||
// int64 X = 1;
|
||||
// float64 Y = 2;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// typ is the type of the concrete entry for a oneof case (e.g. Msg_X).
|
||||
// ityp is the interface type of the oneof field (e.g. isMsg_F).
|
||||
// unmarshal is the unmarshaler for the base type of the oneof case (e.g. int64).
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ func NewDCESecurity(domain Domain, id uint32) (UUID, error) {
|
||||
// NewDCEPerson returns a DCE Security (Version 2) UUID in the person
|
||||
// domain with the id returned by os.Getuid.
|
||||
//
|
||||
// NewDCESecurity(Person, uint32(os.Getuid()))
|
||||
// NewDCESecurity(Person, uint32(os.Getuid()))
|
||||
func NewDCEPerson() (UUID, error) {
|
||||
return NewDCESecurity(Person, uint32(os.Getuid()))
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func NewDCEPerson() (UUID, error) {
|
||||
// NewDCEGroup returns a DCE Security (Version 2) UUID in the group
|
||||
// domain with the id returned by os.Getgid.
|
||||
//
|
||||
// NewDCESecurity(Group, uint32(os.Getgid()))
|
||||
// NewDCESecurity(Group, uint32(os.Getgid()))
|
||||
func NewDCEGroup() (UUID, error) {
|
||||
return NewDCESecurity(Group, uint32(os.Getgid()))
|
||||
}
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID {
|
||||
// NewMD5 returns a new MD5 (Version 3) UUID based on the
|
||||
// supplied name space and data. It is the same as calling:
|
||||
//
|
||||
// NewHash(md5.New(), space, data, 3)
|
||||
// NewHash(md5.New(), space, data, 3)
|
||||
func NewMD5(space UUID, data []byte) UUID {
|
||||
return NewHash(md5.New(), space, data, 3)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func NewMD5(space UUID, data []byte) UUID {
|
||||
// NewSHA1 returns a new SHA1 (Version 5) UUID based on the
|
||||
// supplied name space and data. It is the same as calling:
|
||||
//
|
||||
// NewHash(sha1.New(), space, data, 5)
|
||||
// NewHash(sha1.New(), space, data, 5)
|
||||
func NewSHA1(space UUID, data []byte) UUID {
|
||||
return NewHash(sha1.New(), space, data, 5)
|
||||
}
|
||||
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build js
|
||||
// +build js
|
||||
|
||||
package uuid
|
||||
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build !js
|
||||
// +build !js
|
||||
|
||||
package uuid
|
||||
|
||||
+8
-9
@@ -17,15 +17,14 @@ var jsonNull = []byte("null")
|
||||
// NullUUID implements the SQL driver.Scanner interface so
|
||||
// it can be used as a scan destination:
|
||||
//
|
||||
// var u uuid.NullUUID
|
||||
// err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&u)
|
||||
// ...
|
||||
// if u.Valid {
|
||||
// // use u.UUID
|
||||
// } else {
|
||||
// // NULL value
|
||||
// }
|
||||
//
|
||||
// var u uuid.NullUUID
|
||||
// err := db.QueryRow("SELECT name FROM foo WHERE id=?", id).Scan(&u)
|
||||
// ...
|
||||
// if u.Valid {
|
||||
// // use u.UUID
|
||||
// } else {
|
||||
// // NULL value
|
||||
// }
|
||||
type NullUUID struct {
|
||||
UUID UUID
|
||||
Valid bool // Valid is true if UUID is not NULL
|
||||
|
||||
+6
-4
@@ -187,10 +187,12 @@ func Must(uuid UUID, err error) UUID {
|
||||
}
|
||||
|
||||
// Validate returns an error if s is not a properly formatted UUID in one of the following formats:
|
||||
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||
//
|
||||
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
|
||||
// xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
// {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||
//
|
||||
// It returns an error if the format is invalid, otherwise nil.
|
||||
func Validate(s string) error {
|
||||
switch len(s) {
|
||||
|
||||
+7
-7
@@ -9,7 +9,7 @@ import "io"
|
||||
// New creates a new random UUID or panics. New is equivalent to
|
||||
// the expression
|
||||
//
|
||||
// uuid.Must(uuid.NewRandom())
|
||||
// uuid.Must(uuid.NewRandom())
|
||||
func New() UUID {
|
||||
return Must(NewRandom())
|
||||
}
|
||||
@@ -17,7 +17,7 @@ func New() UUID {
|
||||
// NewString creates a new random UUID and returns it as a string or panics.
|
||||
// NewString is equivalent to the expression
|
||||
//
|
||||
// uuid.New().String()
|
||||
// uuid.New().String()
|
||||
func NewString() string {
|
||||
return Must(NewRandom()).String()
|
||||
}
|
||||
@@ -31,11 +31,11 @@ func NewString() string {
|
||||
//
|
||||
// A note about uniqueness derived from the UUID Wikipedia entry:
|
||||
//
|
||||
// Randomly generated UUIDs have 122 random bits. One's annual risk of being
|
||||
// hit by a meteorite is estimated to be one chance in 17 billion, that
|
||||
// means the probability is about 0.00000000006 (6 × 10−11),
|
||||
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
|
||||
// year and having one duplicate.
|
||||
// Randomly generated UUIDs have 122 random bits. One's annual risk of being
|
||||
// hit by a meteorite is estimated to be one chance in 17 billion, that
|
||||
// means the probability is about 0.00000000006 (6 × 10−11),
|
||||
// equivalent to the odds of creating a few tens of trillions of UUIDs in a
|
||||
// year and having one duplicate.
|
||||
func NewRandom() (UUID, error) {
|
||||
if !poolEnabled {
|
||||
return NewRandomFromReader(rander)
|
||||
|
||||
+4
-3
@@ -19,10 +19,11 @@ var typeSQLScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem()
|
||||
// slice of any dimension.
|
||||
//
|
||||
// For example:
|
||||
// db.Query(`SELECT * FROM t WHERE id = ANY($1)`, pq.Array([]int{235, 401}))
|
||||
//
|
||||
// var x []sql.NullInt64
|
||||
// db.QueryRow(`SELECT ARRAY[235, 401]`).Scan(pq.Array(&x))
|
||||
// db.Query(`SELECT * FROM t WHERE id = ANY($1)`, pq.Array([]int{235, 401}))
|
||||
//
|
||||
// var x []sql.NullInt64
|
||||
// db.QueryRow(`SELECT ARRAY[235, 401]`).Scan(pq.Array(&x))
|
||||
//
|
||||
// Scanning multi-dimensional arrays is not supported. Arrays where the lower
|
||||
// bound is not one (such as `[0:0]={1}') are not supported.
|
||||
|
||||
+46
-59
@@ -27,9 +27,7 @@ You can also connect to a database using a URL. For example:
|
||||
connStr := "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full"
|
||||
db, err := sql.Open("postgres", connStr)
|
||||
|
||||
|
||||
Connection String Parameters
|
||||
|
||||
# Connection String Parameters
|
||||
|
||||
Similarly to libpq, when establishing a connection using pq you are expected to
|
||||
supply a connection string containing zero or more parameters.
|
||||
@@ -42,42 +40,42 @@ them in the options parameter.
|
||||
For compatibility with libpq, the following special connection parameters are
|
||||
supported:
|
||||
|
||||
* dbname - The name of the database to connect to
|
||||
* user - The user to sign in as
|
||||
* password - The user's password
|
||||
* host - The host to connect to. Values that start with / are for unix
|
||||
domain sockets. (default is localhost)
|
||||
* port - The port to bind to. (default is 5432)
|
||||
* sslmode - Whether or not to use SSL (default is require, this is not
|
||||
the default for libpq)
|
||||
* fallback_application_name - An application_name to fall back to if one isn't provided.
|
||||
* connect_timeout - Maximum wait for connection, in seconds. Zero or
|
||||
not specified means wait indefinitely.
|
||||
* sslcert - Cert file location. The file must contain PEM encoded data.
|
||||
* sslkey - Key file location. The file must contain PEM encoded data.
|
||||
* sslrootcert - The location of the root certificate file. The file
|
||||
must contain PEM encoded data.
|
||||
- dbname - The name of the database to connect to
|
||||
- user - The user to sign in as
|
||||
- password - The user's password
|
||||
- host - The host to connect to. Values that start with / are for unix
|
||||
domain sockets. (default is localhost)
|
||||
- port - The port to bind to. (default is 5432)
|
||||
- sslmode - Whether or not to use SSL (default is require, this is not
|
||||
the default for libpq)
|
||||
- fallback_application_name - An application_name to fall back to if one isn't provided.
|
||||
- connect_timeout - Maximum wait for connection, in seconds. Zero or
|
||||
not specified means wait indefinitely.
|
||||
- sslcert - Cert file location. The file must contain PEM encoded data.
|
||||
- sslkey - Key file location. The file must contain PEM encoded data.
|
||||
- sslrootcert - The location of the root certificate file. The file
|
||||
must contain PEM encoded data.
|
||||
|
||||
Valid values for sslmode are:
|
||||
|
||||
* disable - No SSL
|
||||
* require - Always SSL (skip verification)
|
||||
* verify-ca - Always SSL (verify that the certificate presented by the
|
||||
server was signed by a trusted CA)
|
||||
* verify-full - Always SSL (verify that the certification presented by
|
||||
the server was signed by a trusted CA and the server host name
|
||||
matches the one in the certificate)
|
||||
- disable - No SSL
|
||||
- require - Always SSL (skip verification)
|
||||
- verify-ca - Always SSL (verify that the certificate presented by the
|
||||
server was signed by a trusted CA)
|
||||
- verify-full - Always SSL (verify that the certification presented by
|
||||
the server was signed by a trusted CA and the server host name
|
||||
matches the one in the certificate)
|
||||
|
||||
See http://www.postgresql.org/docs/current/static/libpq-connect.html#LIBPQ-CONNSTRING
|
||||
for more information about connection string parameters.
|
||||
|
||||
Use single quotes for values that contain whitespace:
|
||||
|
||||
"user=pqgotest password='with spaces'"
|
||||
"user=pqgotest password='with spaces'"
|
||||
|
||||
A backslash will escape the next character in values:
|
||||
|
||||
"user=space\ man password='it\'s valid'"
|
||||
"user=space\ man password='it\'s valid'"
|
||||
|
||||
Note that the connection parameter client_encoding (which sets the
|
||||
text encoding for the connection) may be set but must be "UTF8",
|
||||
@@ -98,9 +96,7 @@ provided connection parameters.
|
||||
The pgpass mechanism as described in http://www.postgresql.org/docs/current/static/libpq-pgpass.html
|
||||
is supported, but on Windows PGPASSFILE must be specified explicitly.
|
||||
|
||||
|
||||
Queries
|
||||
|
||||
# Queries
|
||||
|
||||
database/sql does not dictate any specific format for parameter
|
||||
markers in query strings, and pq uses the Postgres-native ordinal markers,
|
||||
@@ -125,9 +121,7 @@ For more details on RETURNING, see the Postgres documentation:
|
||||
|
||||
For additional instructions on querying see the documentation for the database/sql package.
|
||||
|
||||
|
||||
Data Types
|
||||
|
||||
# Data Types
|
||||
|
||||
Parameters pass through driver.DefaultParameterConverter before they are handled
|
||||
by this package. When the binary_parameters connection option is enabled,
|
||||
@@ -135,30 +129,27 @@ by this package. When the binary_parameters connection option is enabled,
|
||||
|
||||
This package returns the following types for values from the PostgreSQL backend:
|
||||
|
||||
- integer types smallint, integer, and bigint are returned as int64
|
||||
- floating-point types real and double precision are returned as float64
|
||||
- character types char, varchar, and text are returned as string
|
||||
- temporal types date, time, timetz, timestamp, and timestamptz are
|
||||
returned as time.Time
|
||||
- the boolean type is returned as bool
|
||||
- the bytea type is returned as []byte
|
||||
- integer types smallint, integer, and bigint are returned as int64
|
||||
- floating-point types real and double precision are returned as float64
|
||||
- character types char, varchar, and text are returned as string
|
||||
- temporal types date, time, timetz, timestamp, and timestamptz are
|
||||
returned as time.Time
|
||||
- the boolean type is returned as bool
|
||||
- the bytea type is returned as []byte
|
||||
|
||||
All other types are returned directly from the backend as []byte values in text format.
|
||||
|
||||
|
||||
Errors
|
||||
|
||||
# Errors
|
||||
|
||||
pq may return errors of type *pq.Error which can be interrogated for error details:
|
||||
|
||||
if err, ok := err.(*pq.Error); ok {
|
||||
fmt.Println("pq error:", err.Code.Name())
|
||||
}
|
||||
if err, ok := err.(*pq.Error); ok {
|
||||
fmt.Println("pq error:", err.Code.Name())
|
||||
}
|
||||
|
||||
See the pq.Error type for details.
|
||||
|
||||
|
||||
Bulk imports
|
||||
# Bulk imports
|
||||
|
||||
You can perform bulk imports by preparing a statement returned by pq.CopyIn (or
|
||||
pq.CopyInSchema) in an explicit transaction (sql.Tx). The returned statement
|
||||
@@ -206,9 +197,7 @@ Usage example:
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Notifications
|
||||
|
||||
# Notifications
|
||||
|
||||
PostgreSQL supports a simple publish/subscribe model over database
|
||||
connections. See http://www.postgresql.org/docs/current/static/sql-notify.html
|
||||
@@ -241,9 +230,7 @@ bytes by the PostgreSQL server.
|
||||
You can find a complete, working example of Listener usage at
|
||||
https://godoc.org/github.com/lib/pq/example/listen.
|
||||
|
||||
|
||||
Kerberos Support
|
||||
|
||||
# Kerberos Support
|
||||
|
||||
If you need support for Kerberos authentication, add the following to your main
|
||||
package:
|
||||
@@ -259,10 +246,10 @@ don't have to download unnecessary dependencies.
|
||||
|
||||
When imported, additional connection string parameters are supported:
|
||||
|
||||
* krbsrvname - GSS (Kerberos) service name when constructing the
|
||||
SPN (default is `postgres`). This will be combined with the host
|
||||
to form the full SPN: `krbsrvname/host`.
|
||||
* krbspn - GSS (Kerberos) SPN. This takes priority over
|
||||
`krbsrvname` if present.
|
||||
- krbsrvname - GSS (Kerberos) service name when constructing the
|
||||
SPN (default is `postgres`). This will be combined with the host
|
||||
to form the full SPN: `krbsrvname/host`.
|
||||
- krbspn - GSS (Kerberos) SPN. This takes priority over
|
||||
`krbsrvname` if present.
|
||||
*/
|
||||
package pq
|
||||
|
||||
+11
-11
@@ -330,11 +330,11 @@ func (l *ListenerConn) sendSimpleQuery(q string) (err error) {
|
||||
|
||||
// ExecSimpleQuery executes a "simple query" (i.e. one with no bindable
|
||||
// parameters) on the connection. The possible return values are:
|
||||
// 1) "executed" is true; the query was executed to completion on the
|
||||
// database server. If the query failed, err will be set to the error
|
||||
// returned by the database, otherwise err will be nil.
|
||||
// 2) If "executed" is false, the query could not be executed on the remote
|
||||
// server. err will be non-nil.
|
||||
// 1. "executed" is true; the query was executed to completion on the
|
||||
// database server. If the query failed, err will be set to the error
|
||||
// returned by the database, otherwise err will be nil.
|
||||
// 2. If "executed" is false, the query could not be executed on the remote
|
||||
// server. err will be non-nil.
|
||||
//
|
||||
// After a call to ExecSimpleQuery has returned an executed=false value, the
|
||||
// connection has either been closed or will be closed shortly thereafter, and
|
||||
@@ -541,12 +541,12 @@ func (l *Listener) NotificationChannel() <-chan *Notification {
|
||||
// connection can not be re-established.
|
||||
//
|
||||
// Listen will only fail in three conditions:
|
||||
// 1) The channel is already open. The returned error will be
|
||||
// ErrChannelAlreadyOpen.
|
||||
// 2) The query was executed on the remote server, but PostgreSQL returned an
|
||||
// error message in response to the query. The returned error will be a
|
||||
// pq.Error containing the information the server supplied.
|
||||
// 3) Close is called on the Listener before the request could be completed.
|
||||
// 1. The channel is already open. The returned error will be
|
||||
// ErrChannelAlreadyOpen.
|
||||
// 2. The query was executed on the remote server, but PostgreSQL returned an
|
||||
// error message in response to the query. The returned error will be a
|
||||
// pq.Error containing the information the server supplied.
|
||||
// 3. Close is called on the Listener before the request could be completed.
|
||||
//
|
||||
// The channel name is case-sensitive.
|
||||
func (l *Listener) Listen(channel string) error {
|
||||
|
||||
+11
-14
@@ -25,7 +25,6 @@
|
||||
// Package scram implements a SCRAM-{SHA-1,etc} client per RFC5802.
|
||||
//
|
||||
// http://tools.ietf.org/html/rfc5802
|
||||
//
|
||||
package scram
|
||||
|
||||
import (
|
||||
@@ -43,17 +42,16 @@ import (
|
||||
//
|
||||
// A Client may be used within a SASL conversation with logic resembling:
|
||||
//
|
||||
// var in []byte
|
||||
// var client = scram.NewClient(sha1.New, user, pass)
|
||||
// for client.Step(in) {
|
||||
// out := client.Out()
|
||||
// // send out to server
|
||||
// in := serverOut
|
||||
// }
|
||||
// if client.Err() != nil {
|
||||
// // auth failed
|
||||
// }
|
||||
//
|
||||
// var in []byte
|
||||
// var client = scram.NewClient(sha1.New, user, pass)
|
||||
// for client.Step(in) {
|
||||
// out := client.Out()
|
||||
// // send out to server
|
||||
// in := serverOut
|
||||
// }
|
||||
// if client.Err() != nil {
|
||||
// // auth failed
|
||||
// }
|
||||
type Client struct {
|
||||
newHash func() hash.Hash
|
||||
|
||||
@@ -73,8 +71,7 @@ type Client struct {
|
||||
//
|
||||
// For SCRAM-SHA-256, for example, use:
|
||||
//
|
||||
// client := scram.NewClient(sha256.New, user, pass)
|
||||
//
|
||||
// client := scram.NewClient(sha256.New, user, pass)
|
||||
func NewClient(newHash func() hash.Hash, user, pass string) *Client {
|
||||
c := &Client{
|
||||
newHash: newHash,
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import (
|
||||
//
|
||||
// The following is an example of the contents of Digest types:
|
||||
//
|
||||
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
|
||||
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
|
||||
//
|
||||
// This allows to abstract the digest behind this type and work only in those
|
||||
// terms.
|
||||
|
||||
+5
-6
@@ -19,16 +19,16 @@
|
||||
// More importantly, it provides tools and wrappers to work with
|
||||
// hash.Hash-based digests with little effort.
|
||||
//
|
||||
// Basics
|
||||
// # Basics
|
||||
//
|
||||
// The format of a digest is simply a string with two parts, dubbed the
|
||||
// "algorithm" and the "digest", separated by a colon:
|
||||
//
|
||||
// <algorithm>:<digest>
|
||||
// <algorithm>:<digest>
|
||||
//
|
||||
// An example of a sha256 digest representation follows:
|
||||
//
|
||||
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
|
||||
// sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc
|
||||
//
|
||||
// The "algorithm" portion defines both the hashing algorithm used to calculate
|
||||
// the digest and the encoding of the resulting digest, which defaults to "hex"
|
||||
@@ -42,7 +42,7 @@
|
||||
// obtained, comparisons are cheap, quick and simple to express with the
|
||||
// standard equality operator.
|
||||
//
|
||||
// Verification
|
||||
// # Verification
|
||||
//
|
||||
// The main benefit of using the Digest type is simple verification against a
|
||||
// given digest. The Verifier interface, modeled after the stdlib hash.Hash
|
||||
@@ -50,7 +50,7 @@
|
||||
// writing is complete, calling the Verifier.Verified method will indicate
|
||||
// whether or not the stream of bytes matches the target digest.
|
||||
//
|
||||
// Missing Features
|
||||
// # Missing Features
|
||||
//
|
||||
// In addition to the above, we intend to add the following features to this
|
||||
// package:
|
||||
@@ -58,5 +58,4 @@
|
||||
// 1. A Digester type that supports write sink digest calculation.
|
||||
//
|
||||
// 2. Suspend and resume of ongoing digest calculations to support efficient digest verification in the registry.
|
||||
//
|
||||
package digest
|
||||
|
||||
-1
@@ -20,4 +20,3 @@ type anyArgument struct{}
|
||||
func (a anyArgument) Match(_ interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
+37
-37
@@ -2,89 +2,89 @@
|
||||
//
|
||||
// The traditional error handling idiom in Go is roughly akin to
|
||||
//
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// which when applied recursively up the call stack results in error reports
|
||||
// without context or debugging information. The errors package allows
|
||||
// programmers to add context to the failure path in their code in a way
|
||||
// that does not destroy the original value of the error.
|
||||
//
|
||||
// Adding context to an error
|
||||
// # Adding context to an error
|
||||
//
|
||||
// The errors.Wrap function returns a new error that adds context to the
|
||||
// original error by recording a stack trace at the point Wrap is called,
|
||||
// together with the supplied message. For example
|
||||
//
|
||||
// _, err := ioutil.ReadAll(r)
|
||||
// if err != nil {
|
||||
// return errors.Wrap(err, "read failed")
|
||||
// }
|
||||
// _, err := ioutil.ReadAll(r)
|
||||
// if err != nil {
|
||||
// return errors.Wrap(err, "read failed")
|
||||
// }
|
||||
//
|
||||
// If additional control is required, the errors.WithStack and
|
||||
// errors.WithMessage functions destructure errors.Wrap into its component
|
||||
// operations: annotating an error with a stack trace and with a message,
|
||||
// respectively.
|
||||
//
|
||||
// Retrieving the cause of an error
|
||||
// # Retrieving the cause of an error
|
||||
//
|
||||
// Using errors.Wrap constructs a stack of errors, adding context to the
|
||||
// preceding error. Depending on the nature of the error it may be necessary
|
||||
// to reverse the operation of errors.Wrap to retrieve the original error
|
||||
// for inspection. Any error value which implements this interface
|
||||
//
|
||||
// type causer interface {
|
||||
// Cause() error
|
||||
// }
|
||||
// type causer interface {
|
||||
// Cause() error
|
||||
// }
|
||||
//
|
||||
// can be inspected by errors.Cause. errors.Cause will recursively retrieve
|
||||
// the topmost error that does not implement causer, which is assumed to be
|
||||
// the original cause. For example:
|
||||
//
|
||||
// switch err := errors.Cause(err).(type) {
|
||||
// case *MyError:
|
||||
// // handle specifically
|
||||
// default:
|
||||
// // unknown error
|
||||
// }
|
||||
// switch err := errors.Cause(err).(type) {
|
||||
// case *MyError:
|
||||
// // handle specifically
|
||||
// default:
|
||||
// // unknown error
|
||||
// }
|
||||
//
|
||||
// Although the causer interface is not exported by this package, it is
|
||||
// considered a part of its stable public interface.
|
||||
//
|
||||
// Formatted printing of errors
|
||||
// # Formatted printing of errors
|
||||
//
|
||||
// All error values returned from this package implement fmt.Formatter and can
|
||||
// be formatted by the fmt package. The following verbs are supported:
|
||||
//
|
||||
// %s print the error. If the error has a Cause it will be
|
||||
// printed recursively.
|
||||
// %v see %s
|
||||
// %+v extended format. Each Frame of the error's StackTrace will
|
||||
// be printed in detail.
|
||||
// %s print the error. If the error has a Cause it will be
|
||||
// printed recursively.
|
||||
// %v see %s
|
||||
// %+v extended format. Each Frame of the error's StackTrace will
|
||||
// be printed in detail.
|
||||
//
|
||||
// Retrieving the stack trace of an error or wrapper
|
||||
// # Retrieving the stack trace of an error or wrapper
|
||||
//
|
||||
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
|
||||
// invoked. This information can be retrieved with the following interface:
|
||||
//
|
||||
// type stackTracer interface {
|
||||
// StackTrace() errors.StackTrace
|
||||
// }
|
||||
// type stackTracer interface {
|
||||
// StackTrace() errors.StackTrace
|
||||
// }
|
||||
//
|
||||
// The returned errors.StackTrace type is defined as
|
||||
//
|
||||
// type StackTrace []Frame
|
||||
// type StackTrace []Frame
|
||||
//
|
||||
// The Frame type represents a call site in the stack trace. Frame supports
|
||||
// the fmt.Formatter interface that can be used for printing information about
|
||||
// the stack trace of this error. For example:
|
||||
//
|
||||
// if err, ok := err.(stackTracer); ok {
|
||||
// for _, f := range err.StackTrace() {
|
||||
// fmt.Printf("%+s:%d\n", f, f)
|
||||
// }
|
||||
// }
|
||||
// if err, ok := err.(stackTracer); ok {
|
||||
// for _, f := range err.StackTrace() {
|
||||
// fmt.Printf("%+s:%d\n", f, f)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Although the stackTracer interface is not exported by this package, it is
|
||||
// considered a part of its stable public interface.
|
||||
@@ -265,9 +265,9 @@ func (w *withMessage) Format(s fmt.State, verb rune) {
|
||||
// An error value has a cause if it implements the following
|
||||
// interface:
|
||||
//
|
||||
// type causer interface {
|
||||
// Cause() error
|
||||
// }
|
||||
// type causer interface {
|
||||
// Cause() error
|
||||
// }
|
||||
//
|
||||
// If the error does not implement Cause, the original error will
|
||||
// be returned. If the error is nil, nil will be returned without further
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//go:build go1.13
|
||||
// +build go1.13
|
||||
|
||||
package errors
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user