Documentation
¶
Overview ¶
package gocloudurls helps gocloud.dev packages.
gocloud.dev uses URL to initialize cloud resources like blob, docstore, pubsub and so on. This package normalize URLs of that:
snsSrcPath := "arn:aws:sns:us-east-2:123456789012:mytopic" snsPath, err := gocloudurls.NormalizePubSubURL(snsSrcPath) // -> "awssns:///arn:aws:sns:us-east-2:123456789012:mytopic?region=us-east-2" topic, err := pubsub.OpenTopic(ctx, snsPath)
Index ¶
- func MustNormalizeBlobURL(srcUrl string, environ []string) string
- func MustNormalizeDocStoreURL(srcUrl string, opt ...Option) string
- func MustNormalizePubSubURL(srcUrl string) string
- func NormalizeBlobURL(srcUrl string, environ []string) (string, error)
- func NormalizeDocStoreURL(srcUrl string, opt ...Option) (string, error)
- func NormalizePubSubURL(srcUrl string) (string, error)
- type DynamoDBSchema
- type Field
- type Option
- type SchemaOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustNormalizeBlobURL ¶
MustNormalizeBlobURL is similar to NormalizeBlobURL but raise panic if there is error
func MustNormalizeDocStoreURL ¶
MustNormalizeDocStoreURL is similar to NormalizeDocStoreURL but raise panic if there is error
func MustNormalizePubSubURL ¶
MustNormalizePubSubURL is similar to NormalizePubSubURL but raise panic if there is error
func NormalizeBlobURL ¶
NormalizeBlobURL normalize blob URL. environ assumes os.Environ().
When region is not specified for S3, this function gets region information from AWS_REGION environment variable.
If "mem" is specified, it returns "memblob" URL. It other names specified, it returns fileblob URL.
Example:
- “mem“ → “mem://“
- “folder“ → “file://folder“
- “s3://my-bucket“ → “s3://my-bucket?region=us-west-1“
func NormalizeDocStoreURL ¶
NormalizeDocStoreURL normalizes Document Store URL
Usually, application uses multiple document collections (≒ table in RDB). So it provides API to replace Collection name by application code (config specify until DB location).
Default “KeyName“ is “"_id"“ as same as MongoDB.
If “PartitionKey“ is specified for DynamoDB, “KeyName“ is specified as “sort_key“. This config is ignored for other DocStores.
Examples:
goclodurls.NormalizePubSubURL("mem://", goclodurls.Option{
Collection: "addresses",
})
// "mem://addresses/_id"
goclodurls.NormalizePubSubURL("firestore://my-project", goclodurls.Option{
Collection: "addresses",
})
// "firestore://projects/my-project/databases/(default)/documents/addresses?name_field=_id"
goclodurls.NormalizePubSubURL("firestore://my-project/my-documents/addresses", goclodurls.Option{})
// "firestore://projects/my-project/databases/my-documents/documents/addresses?name_field=_id"
goclodurls.NormalizePubSubURL("dynamodb://", goclodurls.Option{
Collection: "tasks",
})
// "dynamodb://tasks?partition_key=_id"
goclodurls.NormalizePubSubURL("dynamodb://", goclodurls.Option{
Collection: "tasks",
PartitionKey: "job_id"
})
// "dynamodb://tasks?partition_key=job_id&sort_key=_id"
func NormalizePubSubURL ¶
NormalizePubSubURL normalize URL for PubSub.
Examples:
- "arn:aws:sns:us-east-2:123456789012:mytopic" → "awssns:///arn:aws:sns:us-east-2:123456789012:mytopic?region=us-east-2"
- "https://sqs.us-east-2.amazonaws.com/123456789012/myqueue" → "awssqs://https://sqs.us-east-2.amazonaws.com/123456789012/myqueue?region=us-east-2"
- "gcppubsub://myproject/mytopic" → "gcppubsub://projects/myproject/topics/mytopic"
Types ¶
type DynamoDBSchema ¶
DynamoDBSchema creates AWS CLI command to create table.
For example you makes the following struct to handle DynamoDB record:
type Person struct {
Name string `docstore:"name"`
Age int
}
ds, err := NewDynamoDBSchema(&Person{}, MustMustNormalizeDocStoreURL("dynamodb://persons"))
ds.CreateTableCommand()
// returns slice of string.
// "aws", "dynamodb", "create-table", "--table-name", "persons",
// "--attribute-definitions", "AttributeName=name,AttributeType=S",
// "--key-schema", "AttributeName=name,KeyType=HASH",
// "--provisioned-throughput", "ReadCapacityUnits=5,WriteCapacityUnits=5",
func NewDynamoDBSchema ¶
func NewDynamoDBSchema(collectionEntity interface{}, urlString string) (*DynamoDBSchema, error)
NewDynamoDBSchema creates DynamoDBSchema from urlString(it should be a return of NormalizeDocStoreURL), CollectionEntity struct.
func (DynamoDBSchema) CreateTableCommand ¶
func (d DynamoDBSchema) CreateTableCommand(opt ...SchemaOption) []string
CreateTableCommand returns command line to create table.
type Option ¶
type Option struct {
KeyName string
PartitionKey string
Collection string
FileName string
RevisionField string
}
Option is a option for NormalizeDocStoreURL
KeyName is a primary key of document store. Default value is _id.
PartitionKey is only for DynamoDB. If this parameter is specified, KeyName is used as a sort key. If PartitionKey is not specified, KeyName is used as a partitionKey.
If Collection is specified, it returns URL for the Collection. It is good for applications that uses multiple collections.