Skip to content

caoyingjunz/pixiulib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Libpixiu

Library and tools for pixiu

BindConfig

  • 完成 yaml 配置文件的加载
package main

import (
	"fmt"

	"github.com/caoyingjunz/pixiulib/config"
)

type Config struct {
	Default DefaultOption `yaml:"default"`
}

type DefaultOption struct {
	Name string `yaml:"name"`
	Age  int    `yaml:"age"`
}

func main() {
	c := config.New()
	c.SetConfigFile("./config.yaml")
	c.SetConfigType("yaml")

	var cfg Config
	if err := c.Binding(&cfg); err != nil {
		panic(err)
	}

	fmt.Println(cfg)
}

Code demo

Command

  • 执行 linux 命令行
package main

import (
	"fmt"

	"github.com/caoyingjunz/pixiulib/exec"
)

func main() {
	exec := exec.New()

	// 确认命令行是否存在
	if _, err := exec.LookPath("ls"); err != nil {
		panic(err)
	}
	// 属性
	out, err := exec.Command("ls", "-al").CombinedOutput()
	if err != nil {
		panic(err)
	}

	fmt.Println(string(out))
}

Code demo