embedsfs

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: Apache-2.0 Imports: 3 Imported by: 3

README

embedsfs

Golang embedded file system structured processing helper.

Installation

go get -u github.com/coolstina/embedsfs

Usage

Specify embeds relative path
package main

import (
	"embed"
	"fmt"
	"github.com/coolstina/embedsfs"
	"log"
)

//go:embed embeds
var embeds embed.FS

func main() {
	// Initialize embedsfs instance.
	ins := embedsfs.NewEmbedsFS(embeds, embedsfs.WithPath("embeds"))

	// Get golang internal structure embed.FS
	embeds := ins.Embeds()
	fmt.Println(embeds)

	// Get golang embeds filesystem filename
	name := ins.Filename("readme.txt")
	fmt.Println(name)

	// Get golang embeds filesystem filename
	data, err := ins.Content("readme.txt")
	if err != nil {
		log.Fatalf("get embeds file content to failure: %v", err)
	}

	fmt.Println(string(data))
}
Not specify embeds relative path
package main

import (
	"embed"
	"fmt"
	"github.com/coolstina/embedsfs"
	"log"
)

//go:embed embeds
var embeds embed.FS

func main() {
	// Initialize embedsfs instance.
	ins := embedsfs.NewEmbedsFS(embeds)

	// Get golang internal structure embed.FS
	embeds := ins.Embeds()
	fmt.Println(embeds)

	// Get golang embeds filesystem filename
	name := ins.Filename("embeds/readme.txt")
	fmt.Println(name)

	// Get golang embeds filesystem filename
	data, err := ins.Content("embeds/readme.txt")
	if err != nil {
		log.Fatalf("get embeds file content to failure: %v", err)
	}

	fmt.Println(string(data))
}

LICENSE

Author

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmbedsFS

type EmbedsFS struct {
	// contains filtered or unexported fields
}

EmbedsFS custom definition structure.

func NewEmbedsFS

func NewEmbedsFS(embeds embed.FS, options ...Option) *EmbedsFS

NewEmbedsFS returns a new EmbedsFS instance

func (*EmbedsFS) Content

func (embeds *EmbedsFS) Content(name string) ([]byte, error)

Content returns embed filename contains embed.FS fill path

func (*EmbedsFS) Embeds

func (embeds *EmbedsFS) Embeds() embed.FS

Embeds returns a embeds filesystem structure

func (*EmbedsFS) Filename

func (embeds *EmbedsFS) Filename(name string) string

Filename returns embed filename contains embed.FS fill path

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithPath

func WithPath(path string) Option

WithPath specify embed filesystem relative path.

type OptionFunc

type OptionFunc func(option *option)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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