fullpath

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 6 Imported by: 0

README

fullpath

完整路径生成

使用
package fullpath_test

import (
	"fmt"
	"testing"

	"github.com/Drelf2018/fullpath"
)

type Path struct {
	Root    string `default:"resource"`
	Views   string `default:"views" abs:"Root"`
	Public  string `default:"public" abs:"Root"`
	Posts   string `default:"posts.db" abs:"Public"`
	Users   string `default:"users.db" abs:"Root"`
	Log     string `default:".log" abs:"Root"`
	Index   string `default:"index.html" abs:"Views"`
	Version string `default:".version" abs:"Views"`
	Full    *Path  `default:"Init;Abs;Self;Parent"`
}

func (p *Path) Init(_ any) {
	p.Views = "pages"
}

func (p *Path) Self(_ *Path) {
	fmt.Printf("p: %v\n", p)
}

func (*Path) Parent(parent *Path) {
	fmt.Printf("parent: %v\n", parent)
}

func TestPath(t *testing.T) {
	result := fullpath.Default(&Path{})
	fmt.Printf("result: %v\n", result)
}
控制台
p: &{resource resource\pages resource\public resource\public\posts.db resource\users.db resource\.log resource\pages\index.html resource\pages\.version <nil>}
parent: &{resource views public posts.db users.db .log index.html .version 0xc00019e090}
result: &{resource views public posts.db users.db .log index.html .version 0xc00019e090}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMethod  = errors.New("tag method name not found")
	ErrPtrNil  = errors.New("pointer parament is nil")
	ErrTypeStr = errors.New("value v must be a pointer to a struct")
	ErrTagAbs  = errors.New("tag abs must be a field name")
	ErrTagType = errors.New("tag default's type didn't match")
)

Functions

func Abs

func Abs[P any, T *P](dst, src T) T

func Default

func Default[P any, T *P](v T) T

func Graph

func Graph(cap int) graph

Types

This section is empty.

Jump to

Keyboard shortcuts

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