https://github.com/future-architect/gocloudurls
gcloud.dev helper to manage urls
https://github.com/future-architect/gocloudurls
Last synced: 10 months ago
JSON representation
gcloud.dev helper to manage urls
- Host: GitHub
- URL: https://github.com/future-architect/gocloudurls
- Owner: future-architect
- License: apache-2.0
- Created: 2019-11-05T09:34:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-06T01:14:23.000Z (over 6 years ago)
- Last Synced: 2025-08-15T13:57:42.696Z (10 months ago)
- Language: Go
- Size: 24.4 KB
- Stars: 1
- Watchers: 12
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gocloudurls
[](https://godoc.org/github.com/future-architect/gocloudurls)
gocloudurls package is a helper for gocloud.dev.
Now it provides three functions for
* PubSub
* DocStore
* Blob
## Purpose
It makes configuration easy for gocloud.dev.
gocloud.dev requires special form of URLs to specify cloud resources.
This package normalize more human readable/writable config values into gocloud.dev ones.
## Functions
### ``func NormalizeBlobURL(srcUrl string) (string, error)``
It normalize shorter version of blob URLs into gocloud.dev acceptable URLs.
Examples:
* ``mem`` → ``mem://``
* ``folder`` → ``file://folder``
* ``s3://my-bucket`` → ``s3://my-bucket?region=us-west-1``
It gets AWS region name form ``AWS_REGION`` environment variable that is acceptable in AWS Lambda.
``MustNormalizeBlobURL`` raise panic if there is error.
### ``func NormalizePubSubURL(srcUrl string) (string, error)``
It normalizes shorter version of PubSub/SQS/SNS identifier into gocloud.dev acceptable URLs.
Examples:
```go
gocloudurls.NormalizePubSubURL("arn:aws:sns:us-east-2:123456789012:mytopic")
// "awssns:///arn:aws:sns:us-east-2:123456789012:mytopic?region=us-east-2"
```
```go
gocloudurls.NormalizePubSubURL("https://sqs.us-east-2.amazonaws.com/123456789012/myqueue")
// "awssqs://https://sqs.us-east-2.amazonaws.com/123456789012/myqueue?region=us-east-2"
```
```go
gocloudurls.NormalizePubSubURL("gcppubsub://myproject/mytopic")
// "gcppubsub://projects/myproject/topics/mytopic"
```
``MustNormalizePubSubURL`` raise panic if there is error.
### ``func NormalizeDocStoreURL(srcUrl string, opt Option) (string, error)``
```go
type Option struct {
KeyName string
PartitionKey string
Collection string
}
```
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:
```go
goclodurls.NormalizeDocStoreURL("mem://", goclodurls.Option{
Collection: "addresses",
})
// "mem://addresses/_id"
```
```go
goclodurls.NormalizeDocStoreURL("firestore://my-project", goclodurls.Option{
Collection: "addresses",
})
// "firestore://projects/my-project/databases/(default)/documents/addresses?name_field=_id"
```
```go
goclodurls.NormalizeDocStoreURL("firestore://my-project/my-documents/addresses", goclodurls.Option{})
// "firestore://projects/my-project/databases/my-documents/documents/addresses?name_field=_id"
```
```go
goclodurls.NormalizeDocStoreURL("dynamodb://", goclodurls.Option{
Collection: "tasks",
})
// "dynamodb://tasks?partition_key=_id"
```
```go
goclodurls.NormalizeDocStoreURL("dynamodb://", goclodurls.Option{
Collection: "tasks",
PartitionKey: "job_id"
})
// "dynamodb://tasks?partition_key=job_id&sort_key=_id"
```
``MustNormalizeDocStoreURL`` raise panic if there is error.
## Struct
``DynamoDBSchema`` creates AWS CLI command to create table.
For example you makes the following struct to handle DynamoDB record:
```go
type Person struct {
Name string `docstore:"name"`
Age int
}
```
You can get AWS command options:
```go
ds, err := NewDynamoDBSchema(&Person{}, MustMustNormalizeDocStoreURL("dynamodb://persons"))
ds.CreateTableCommand()
// It 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",
```
If you can modify Read/Write capacity unis, you can use SchemaOption:
```go
ds.CreateTableCommand(SchemaOption{
ReadCapacityUnits: 10,
WriteCapacityUnits: 10,
})
```
## License
Apache 2