gourn

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

GoURN

GitHub Workflow Status (branch) Go Report Card Go Reference

GoURN is a Go package that provides a comprehensive URN (Uniform Resource Name) parsing library. It follows the specifications outlined in RFC 2141.

Features

  • Parse valid URNs according to RFC 2141.
  • Normalize the parsed URN to ensure consistency.
  • Convert parsed URNs to valid string representation.
  • Serialize and deserialize URNs to/from JSON format.

Installation

To use GoURN in your Go project, install Go and run go get:

$ go get -u github.com/companyinfo/gourn

Usage

Here's a quick example of how to use GoURN to parse and work with URNs:

package main

import (
	"fmt"
	"github.com/companyinfo/gourn"
	"log"
)

func main() {
	urnString := "urn:example:resource"
	urn, err := gourn.Parse(urnString)
	if err != nil {
		log.Print("Unable to parse the URN: ", err)

		return
	}

	fmt.Println("NID:", urn.NID)
	fmt.Println("NSS:", urn.NSS)
	fmt.Println("URN String:", urn)
}

This will print:

NID: example
NSS: resource
URN String: urn:example:resource

For more detailed usage examples, please refer to the code and tests in this repository.

Contribution

Contributions to GoURN are welcome! If you find a bug, want to add a feature, or have suggestions for improvements, feel free to open issues or submit pull requests.

License

Copyright 2023 Company.info

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidURN represents an error for invalid URN
	ErrInvalidURN = errors.New("invalid URN")
)

Functions

This section is empty.

Types

type NullURN

type NullURN struct {
	URN   URN
	Valid bool // Valid is true if URN is not NULL
}

NullURN represents a URN that may be null. NullURN implements the Scanner interface, so it can be used as a scan destination:

var s NullURN
err := db.QueryRow("SELECT urn FROM foo WHERE id=?", id).Scan(&s)
...
if s.Valid {
   // use s.URN
} else {
   // NULL value
}

func (*NullURN) Scan

func (nu *NullURN) Scan(value any) error

Scan implements the Scanner interface.

func (*NullURN) Value

func (nu *NullURN) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type URN

type URN struct {
	NID string // Namespace identifier
	NSS string // Namespace specific string
}

URN represents a Uniform Resource Name.

The general form is: urn:<nid>:<nss> Compliant with https://tools.ietf.org/html/rfc2141.

func Parse

func Parse(u string) (*URN, error)

Parse is responsible to create a URN instance from a byte array matching the correct URN syntax.

func (*URN) MarshalJSON

func (u *URN) MarshalJSON() ([]byte, error)

MarshalJSON marshals the URN to JSON string.

func (*URN) Scan

func (u *URN) Scan(v interface{}) error

Scan implements the database/sql scanner interface

func (*URN) String

func (u *URN) String() string

String represents the URN struct in a valid URN string.

func (*URN) UnmarshalJSON

func (u *URN) UnmarshalJSON(bytes []byte) error

UnmarshalJSON unmarshals a URN from JSON string.

func (*URN) Value

func (u *URN) Value() (driver.Value, error)

Value implements the database/sql valuer interface

Jump to

Keyboard shortcuts

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