arn

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2017 License: MIT Imports: 2 Imported by: 0

README

Amazon Resource Name

Build Status Go Report Card GoDoc

Amazon Resource Name parser and validator library.

Amazon Resource Name (ARN) is Amazon's standard for identifying resources. Although there are Amazon specific components in it (eg. region), in most of the cases it perfectly fits.

This library provides a way to validate and parse ARNs.

Read about ARNs in the official documentation.

Installation

$ go get github.com/goph/arn

Usage

package main

import(
	"fmt"
	
	"github.com/goph/arn"
)

func main() {
	resourceName, err := arn.Parse("arn:aws:rds:eu-west-1:123456789012:db:mysql-db")
	if err != nil {
		panic(err)
	}

	fmt.Println(resourceName.String())
}

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("invalid ARN")

ErrInvalid is returned when an ARN fails validation checks.

Functions

func Validate

func Validate(arn string) error

Validate checks whether the input is a valid ARN.

Types

type ResourceName

type ResourceName struct {
	// Scheme is always "arn". Placed here for future compatibility.
	Scheme string

	// Partition is the partition that the resource is in.
	Partition string

	// Service identifies the actual product.
	Service string

	// Region is the region the resource resides in.
	// This component can sometimes be omitted, depends on the implementation.
	Region string

	// AccountID is the ID of the account that owns the resource.
	// This can be ignored in most of the cases when the resource itself can be identified
	// (eg. when the resource is unique).
	AccountID string

	// ResourceType is the optional type of resource.
	// Whether it is required or not depends entirely on the implementation.
	ResourceType string

	// ResourceDelimiter delimits the ResourceType and the Resource.
	// It is necessary to be stored here in order to restore the original Scheme.
	ResourceDelimiter string

	// Resource is the actual identifier of the resource.
	Resource string
}

ResourceName represents the actual resource name.

func Parse

func Parse(arn string) (*ResourceName, error)

Parse accepts an ARN parses it into a ResourceName.

Example
package main

import (
	"fmt"

	"github.com/goph/arn"
)

func main() {
	resourceName, err := arn.Parse("arn:aws:rds:eu-west-1:123456789012:db:mysql-db")
	if err != nil {
		panic(err)
	}

	fmt.Println(resourceName.String())

}
Output:
arn:aws:rds:eu-west-1:123456789012:db:mysql-db

func (*ResourceName) ResourceValue

func (n *ResourceName) ResourceValue() string

ResourceValue returns the last component of the ARN.

func (*ResourceName) String

func (n *ResourceName) String() string

String returns the original ARN.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL