common

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 10 Imported by: 12

Documentation

Index

Examples

Constants

View Source
const (
	ConfigFileName    = "config"
	ApplicationFolder = "applications"
	DatabaseFolder    = "databases"
	DomainFolder      = "domains"
	FunctionFolder    = "functions"
	LibraryFolder     = "libraries"
	MessagingFolder   = "messaging"
	ServiceFolder     = "services"
	SmartOpsFolder    = "smartops"
	StorageFolder     = "storages"
	WebsiteFolder     = "websites"
)

Variables

This section is empty.

Functions

func StringToTime

func StringToTime(_time string) (uint64, error)

StringToTime Converts _time a unit in form 1h10m43s to a uint64 representing nanoseconds

Example
package main

import (
	"fmt"
	"log"

	"github.com/taubyte/go-project-schema/common"
)

func main() {
	unit, err := common.StringToTime("3h")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(unit)

	unit, err = common.StringToTime("3h10m")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(unit)

	unit, err = common.StringToTime("10m")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(unit)

	unit, err = common.StringToTime("5000ns")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(unit)

	unit, err = common.StringToTime("")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(unit)

}
Output:

10800000000000
11400000000000
600000000000
5000
0

func StringToUnits

func StringToUnits(size string) (uint64, error)

StringToUnits converts size in a unit in form 1.3KB OR 6.3GB to bytes

Example
package main

import (
	"fmt"
	"log"

	"github.com/taubyte/go-project-schema/common"
)

func main() {
	size, err := common.StringToUnits("64MB")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(size)

	size, err = common.StringToUnits("64MB10KB")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(size)

}
Output:

64000000
64010000

func TimeToString

func TimeToString[T constraints.Integer | time.Duration](_time T) string

TimeToString Converts _time a unit64 representing nanoseconds to a unit in form 1h10m43s

Example
package main

import (
	"fmt"
	"time"

	"github.com/taubyte/go-project-schema/common"
)

func main() {
	unit := common.TimeToString(3 * time.Hour)
	fmt.Println(unit)

	unit = common.TimeToString(3*time.Hour + 10*time.Minute)
	fmt.Println(unit)

	unit = common.TimeToString(10 * time.Minute)
	fmt.Println(unit)

	unit = common.TimeToString(15*time.Millisecond + 10*time.Nanosecond)
	fmt.Println(unit)

	unit = common.TimeToString(10 * time.Microsecond)
	fmt.Println(unit)

}
Output:

3h
3h10m
10m
15.00001ms
10µs

func UnitsToString

func UnitsToString[T constraints.Integer](size T) string

UnitsToString converts size in bytes to a unit in form 1.3KB OR 6.3GB

Example
package main

import (
	"fmt"

	"github.com/alecthomas/units"
	"github.com/taubyte/go-project-schema/common"
)

func main() {

	unit := common.UnitsToString(64 * units.MB)
	fmt.Println(unit)

	unit = common.UnitsToString(64*units.MB + 10*units.KB)
	fmt.Println(unit)

}
Output:

64MB
64MB10KB

Types

type Mapper

type Mapper []struct {
	Field      string
	IfNotEmpty bool
	Callback   func() error
}

func (Mapper) Run

func (m Mapper) Run(obj interface{}) (err error)

type Resource

type Resource[T structureSpec.Structure] interface {
	Set(sync bool, ops ...basic.Op) (err error)
	Delete(attributes ...string) (err error)
	Prettify(p pretty.Prettier) map[string]interface{}
	SetWithStruct(sync bool, structure T) error
}

Jump to

Keyboard shortcuts

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