Skip to content

Latest commit

 

History

History
68 lines (55 loc) · 2.36 KB

README.md

File metadata and controls

68 lines (55 loc) · 2.36 KB

Go SaltStack

go 调用 salt-api 接口

安装

go get github.com/daixijun/go-salt

使用

package main

import (
	"context"
	"fmt"

	salt "github.com/daixijun/go-salt/v2"
)

func main() {

	ctx := context.TODO()
	// 初始化客户端
	client := salt.NewClient(
		salt.WithEndpoint("https://saltapi.example.com"),
		salt.WithUsername("saltapi"),
		salt.WithPassword("saltapi"),
		salt.WithAuthBackend("pam"),
		salt.WithInsecure(),
	)
	if err := client.Login(ctx); err != nil {
		panic(err)
	}

	// 列表 minions
	minions, err := client.ListMinions(ctx)
	if err != nil {
		panic(err)
	}
	fmt.Println(minions)

	// 执行命令
	resp, err := client.LocalClient(ctx, "cmd.run", []string{"whoami"}, salt.WithGlobTarget("minion1"))
	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}

支持的接口