storages

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: 6 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Description

func Description(value string) basic.Op

func Id

func Id(value string) basic.Op

func Match

func Match(value string) basic.Op

func Object

func Object(versioning bool, size string) basic.Op

if bucket type Object

func Public

func Public(value bool) basic.Op

func Regex

func Regex(value bool) basic.Op

func SmartOps

func SmartOps(value []string) basic.Op

func Streaming

func Streaming(ttl string, size string) basic.Op

func Tags

func Tags(value []string) basic.Op

Types

type Getter

type Getter interface {
	basic.ResourceGetter[*structureSpec.Storage]
	Match() string
	Regex() bool
	Type() string

	// if bucket type Object
	Public() bool
	Versioning() bool

	// if bucket type Streaming
	TTL() string

	// independent
	Size() string
	SmartOps() []string
}

func Yaml

func Yaml(name, application string, yamlData []byte) (Getter, error)

type Storage

type Storage interface {
	Get() Getter
	common.Resource[*structureSpec.Storage]
}
Example
package main

import (
	"fmt"

	"github.com/spf13/afero"
	"github.com/taubyte/go-project-schema/project"
	"github.com/taubyte/go-project-schema/storages"
)

func main() {
	// Create a new file system in memory
	fs := afero.NewMemMapFs()

	// Open a new project with a virtual file system
	project, err := project.Open(project.VirtualFS(fs, "/"))
	if err != nil {
		return
	}

	// Create or open an storage
	stg, err := project.Storage("test_stg", "")
	if err != nil {
		return
	}

	// Set and write storage fields
	err = stg.Set(true,
		storages.Id("QmaEBKzOyrYL1D6gtqD86Nyr2hvXAxWHcMCu9ffxLaByMc"),
		storages.Description("a basic object storage for storing user information"),
		storages.Tags([]string{"tag1", "tag2"}),
		storages.Match("users"),
		storages.Regex(false),
		storages.Public(true),
		storages.Object(true, "15GB"),
	)
	if err != nil {
		return
	}

	// Display the Description
	fmt.Println(stg.Get().Description())

	// Open the config.yaml of the storage
	config, err := afero.ReadFile(fs, "/storages/test_stg.yaml")
	if err != nil {
		return
	}

	// Print config.yaml
	fmt.Println(string(config))

}
Output:

a basic object storage for storing user information
id: QmaEBKzOyrYL1D6gtqD86Nyr2hvXAxWHcMCu9ffxLaByMc
description: a basic object storage for storing user information
tags:
    - tag1
    - tag2
match: users
useRegex: false
access:
    network: all
object:
    versioning: true
    size: 15GB

func Open

func Open(seer *seer.Seer, name string, application string) (Storage, error)

Jump to

Keyboard shortcuts

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