egFilePath

package
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2023 License: MIT Imports: 5 Imported by: 7

Documentation

Overview

Package egFilePath provides filepath manupilation functionalities.

egFilePath provides filepath manupilation manipulation, provided by "path/filepath".

Example

for standalone test, change package to `main` and the next func def to, func main() {

package main

import (
	"os"

	"github.com/go-easygen/easygen"
	"github.com/go-easygen/easygen/egFilePath"
)

// for standalone test, change package to `main` and the next func def to,
// func main() {
func main() {
	tmpl0 := easygen.NewTemplate().Customize()
	tmpl := tmpl0.Funcs(easygen.FuncDefs()).Funcs(egFilePath.FuncDefs())
	err := easygen.Process0(tmpl, os.Stdout,
		// https://godoc.org/path/filepath
		"Base: {{fpBase `/a/b.c`}}, {{fpBase `/b.c/`}}, {{fpBase `./b.c`}}, {{fpBase `b.c`}}\n"+
			"Clean: {{fpClean `/a//b.c/./..`}}, {{fpClean `//b.c///`}}, {{fpClean `/../b.c`}}\n"+
			"Dir: {{fpDir `/a/b/c`}}, {{fpDir `/b/c/`}}, {{fpDir `./b/c`}}, {{fpDir `b.c`}}\n"+
			"Ext: {{fpExt `index`}}, {{fpExt `index.js`}}, {{fpExt `main.test.js`}}\n"+
			"Join: {{fpJoin `/a` `b` `c` `a//` `//b////c`}}, {{fpJoin `a` `b/c`}}, {{fpJoin `a/b` `c`}}\n"+
			"Rel: {{fpRel `/a` `/a/b/c`}}, {{fpRel `/a` `/b/c`}}\n"+

			// Two error cases, uncomment to verify
			// "{{fpRel `/a` `./b/c`}}, {{isDir `not-exist`}}.\n"+

			"IsDir: {{isDir `.`}}.\n"+
			"Basename: {{basename `/a/b.c`}}, {{basename `/b.c/`}}, {{basename `b.c`}}, {{basename `bc`}}",
		"../test/var0")

	if err != nil {
		panic(err)
	}
}

// To show the full code in GoDoc
type dummy struct {
}
Output:

Base: b.c, b.c, b.c, b.c
Clean: /a, /b.c, /b.c
Dir: /a/b, /b/c, b, .
Ext: , .js, .js
Join: /a/b/c/a/b/c, a/b/c, a/b/c
Rel: b/c, ../b/c
IsDir: true.
Basename: b, b, b, bc

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basename

func Basename(s string) string

Basename returns basename(path)

func FuncDefs

func FuncDefs() template.FuncMap

FuncDefs returns the custom definition mapping for this specific package.

func IsDir

func IsDir(path string) bool

IsDir returns true if path is dir

Types

type EgFilePath

type EgFilePath struct {
	*easygen.EgBase
}

EgFilePath -- EasyGen FilePath manupilation functionalities

fpAbs is wrapper for filepath.Abs
fpBase is wrapper for filepath.Base
fpClean is wrapper for filepath.Clean
fpDir is wrapper for filepath.Dir
fpEvalSymlinks is wrapper for filepath.EvalSymlinks
fpExt is wrapper for filepath.Ext
fpFromSlash is wrapper for filepath.FromSlash
fpGlob is wrapper for filepath.Glob
fpHasPrefix is wrapper for filepath.HasPrefix
fpIsAbs is wrapper for filepath.IsAbs
fpJoin is wrapper for filepath.Join
fpMatch is wrapper for filepath.Match
fpRel is wrapper for filepath.Rel
fpSplitList is wrapper for filepath.SplitList
fpToSlash is wrapper for filepath.ToSlash
fpVolumeName is wrapper for filepath.VolumeName

isDir is template function for IsDir
basename is template function for Basename

Jump to

Keyboard shortcuts

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