bt_go_sdk

package module
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 10 Imported by: 1

README

用 http 对接 go 和宝塔 api 的 sdk

参考 https://www.bt.cn/bbs/thread-20376-1-1.html

  • 返回 json 自动解析为 struct
  • 保存返回的 cookies 并在之后的请求中使用来提高效率
  • 已基本完成 api-doc.pdf 中的所有接口
  • 所有 API 通过单元测试 测试版本为 6.9.8(免费版)

使用:

package main

import "github.com/minoic/bt-go-sdk"

func main() {
	c:=bt_go_sdk.NewClient("http://localhost:8888","qviqWLiiUB623bfzJqQ37OGUEXwOXtVN")
	ret,err:=c.GetNetWork()
	if err != nil {
		// handle error
	}
	// handle return data
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MD5

func MD5(s string) string

MD5 Generate 32-bit MD5 strings

Types

type Client

type Client struct {
	BTAddress string // 目标宝塔面板地址 eg.http://10.0.0.14:8888 结尾不要有斜杠
	BTKey     string // API Key 还需要添加 IP 白名单

	Timeout time.Duration
	// contains filtered or unexported fields
}

Client 每个 Client 对象对应一个宝塔面板 先实例化再调用接口

func NewClient

func NewClient(address string, key string, timeout ...time.Duration) *Client

NewClient 填入两个参数来实例化 Client 对象

func (*Client) AddDomain

func (this *Client) AddDomain(id int64, webname string, domain string) (RespMSG, error)

AddDomain 网站添加域名

func (*Client) AddSite

func (this *Client) AddSite(params *ReqAddSite) (RespAddSite, error)

AddSite 创建网站

func (*Client) CloseHasPwd

func (this *Client) CloseHasPwd(id int64) (RespMSG, error)

CloseHasPwd 关闭网站密码访问

func (*Client) CloseLimitNet

func (this *Client) CloseLimitNet(id int64) (RespMSG, error)

CloseLimitNet 关闭流量限制

func (*Client) DelDomain

func (this *Client) DelDomain(id int64, webname string, domain string, port int64) (RespMSG, error)

DelDomain 网站删除域名

func (*Client) DeleteSite

func (this *Client) DeleteSite(params *ReqDeleteSite) (RespMSG, error)

DeleteSite 删除网站

func (*Client) DeleteSiteBackup

func (this *Client) DeleteSiteBackup(id int64) (RespMSG, error)

DeleteSiteBackup 删除网站备份

func (*Client) GetDirUserINI

func (this *Client) GetDirUserINI(id int64, path string) (RespUserINI, error)

GetDirUserINI 取回防跨站配置/运行目录/日志开关状态/可设置的运行目录列表/密码访问状态

func (*Client) GetDiskInfo

func (this *Client) GetDiskInfo() (DiskInfo, error)

GetDiskInfo 获取磁盘分区信息

func (*Client) GetFile

func (this *Client) GetFile(path string) (RespGetFile, error)

GetFile 获取文件

func (*Client) GetIndex

func (this *Client) GetIndex(id int64) (string, error)

GetIndex 取默认文档信息

func (*Client) GetLimitNet

func (this *Client) GetLimitNet(id int64) (RespLimitNet, error)

GetLimitNet 获取流量限制相关配置(仅支持 nginx)

func (*Client) GetNetWork

func (this *Client) GetNetWork() (NetWork, error)

GetNetWork 获取实时状态信息(CPU、内存、网络、负载)

func (*Client) GetPHPVersion

func (this *Client) GetPHPVersion() (PHPVersions, error)

GetPHPVersion 获取已安装的 PHP 版本列表

func (*Client) GetRewriteList

func (this *Client) GetRewriteList(siteName string) (RewriteList, error)

GetRewriteList 获取网站可选伪静态列表

func (*Client) GetSiteBackups

func (this *Client) GetSiteBackups(params *ReqSiteBackups) (RespSiteBackups, error)

GetSiteBackups 获取网站备份列表

func (*Client) GetSiteDomains

func (this *Client) GetSiteDomains(search int64) (SiteDomains, error)

GetSiteDomains 获取网站域名列表

func (*Client) GetSites

func (this *Client) GetSites(params *ReqSites) (RespSites, error)

GetSites 获取网站列表

func (*Client) GetSystemTotal

func (this *Client) GetSystemTotal() (SystemTotal, error)

GetSystemTotal 获取系统基础统计

func (*Client) GetTaskCount

func (this *Client) GetTaskCount() int

GetTaskCount 检查是否有安装任务

func (*Client) GetUpdateStatus

func (this *Client) GetUpdateStatus(check bool, force bool) (UpdateStatus, error)

GetUpdateStatus 检查面板更新

func (*Client) Raw deprecated

func (this *Client) Raw(data map[string][]string, endpoint string) ([]byte, error)

Deprecated: Used only for debug 执行无封装 API 调用

func (*Client) SetDirUserINI

func (this *Client) SetDirUserINI(path string) (RespMSG, error)

SetDirUserINI 设置防跨站状态(自动取反)

func (*Client) SetFile

func (this *Client) SetFile(path string, body string) (RespMSG, error)

SetFile 修改文件(无法新建文件)

func (*Client) SetHasPwd

func (this *Client) SetHasPwd(id int64, user string, pwd string) (RespMSG, error)

SetHasPwd 打开并设置网站密码访问

func (*Client) SetIndex

func (this *Client) SetIndex(id int64, Index string) (RespMSG, error)

SetIndex 设置默认文档 ep. Index : "index.php,index.html,index.htm,default.php,default.htm,default.html"

func (*Client) SetLimitNet

func (this *Client) SetLimitNet(id int64, perServer int64, perIP int64, limitRate int64) (RespMSG, error)

SetLimitNet 开启或保存流量限制配置(仅支持 nginx)

func (*Client) SetLogsOpen

func (this *Client) SetLogsOpen(id int64) (RespMSG, error)

SetLogsOpen 设置是否写访问日志

func (*Client) SetPath

func (this *Client) SetPath(id int64, path string) (RespMSG, error)

SetPath 修改网站根目录

func (*Client) SetRunPath

func (this *Client) SetRunPath(id int64, path string) (RespMSG, error)

SetRunPath 修改网站运行目录 path 填相对目录 比如 "/public"

func (*Client) SetSiteEdate

func (this *Client) SetSiteEdate(id int64, edate string) (RespMSG, error)

SetSiteEdate 设置网站过期时间 格式 “0000-00-00”(全 0 为永久)

func (*Client) SetSitePS

func (this *Client) SetSitePS(id int64, ps string) (RespMSG, error)

SetSitePS 设置网站备注

func (*Client) SiteBackup

func (this *Client) SiteBackup(id int64) (RespMSG, error)

SiteBackup 创建网站备份

func (*Client) StartSite

func (this *Client) StartSite(id int64, name string) (RespMSG, error)

StartSite 启动网站

func (*Client) StopSite

func (this *Client) StopSite(id int64, name string) (RespMSG, error)

StopSite 停止网站

type DiskInfo

type DiskInfo []struct {
	Path   string   `json:"path"`
	Inodes []string `json:"inodes"`
	Size   []string `json:"size"`
}

DiskInfo 获取磁盘分区信息 URI 地址:/system?action=GetDiskInfo

type NetWork

type NetWork struct {
	Load struct {
		Max     int     `json:"max"`     // 最高值
		Safe    float64 `json:"safe"`    // 安全值
		One     float64 `json:"one"`     // 1 分钟
		Five    float64 `json:"five"`    // 5 分钟
		Limit   int     `json:"limit"`   // 限制
		Fifteen float64 `json:"fifteen"` // 10 分钟
	} `json:"load"` // 负载实时信息
	Down      float64 `json:"down"`      // 下行流量 (KB)
	DownTotal int64   `json:"downTotal"` // 总接收 (Byte)
	Version   string  `json:"version"`   // 面板版本
	Mem       struct {
		MemFree     int `json:"memFree"`     // 可用内存(MB)
		MemTotal    int `json:"memTotal"`    // 总共内存(MB)
		MemCached   int `json:"memCached"`   // 缓存化内存(MB)
		MemBuffers  int `json:"memBuffers"`  // 系统缓冲(MB)
		MemRealUsed int `json:"memRealUsed"` // 实际使用内存(MB)
	} `json:"mem"` // 内存实时信息
	Up        float64 `json:"up"`        // 上行流量(KB)
	UpTotal   int64   `json:"upTotal"`   // 总发送 (Byte)
	UpPackets int     `json:"upPackets"` // 总发包 (个)
	Disk      []struct {
		Path   string   `json:"path"`   // 挂载点
		Inodes []string `json:"inodes"` // Inode使用信息 数组同下
		Size   []string `json:"size"`   // 0-总共(GB) 1-已用(GB) 2-可用(GB) 3-使用率(百分比 带%)
	} `json:"disk"` // 磁盘
	DownPackets int           `json:"downPackets"` // 总收包(个)
	CPU         []interface{} `json:"cpu"`         // 0-总体使用率 1-核心数 2-[0-CPU0 1-CPU1]使用率 3-CPU型号
}

NetWork 获取实时状态信息(CPU、内存、网络、负载) URI 地址:/system?action=GetNetWork

type PHPVersions

type PHPVersions []struct {
	Version string `json:"version"`
	Name    string `json:"name"`
}

PHPVersions 获取已安装的 PHP 版本列表 URI 地址:/site?action=GetPHPVersion

type ReqAddSite

type ReqAddSite struct {
	WebName struct {
		Domain     string   `json:"domain"`     // 必填
		DomainList []string `json:"domainlist"` // 必填
		Count      int      `json:"count"`      // 必填
	}
	Path         string // 必填
	TypeID       int64  // 必填
	Type         string // 必填
	Version      int64  // 必填
	Port         int64  // 必填
	PS           string // 必填
	FTP          bool   // 必填
	FTPUserName  string // FTP 为 true 时 必填
	FTPPassword  string // FTP 为 true 时 必填
	SQL          bool   // 必填
	Codeing      string // SQL 为 true 时 必填
	DataUser     string // SQL 为 true 时 必填
	DataPassword string // SQL 为 true 时 必填
}

ReqAddSite 创建网站 URI 地址:/site?action=AddSite

type ReqDeleteSite

type ReqDeleteSite struct {
	ID       int64  // 必填
	WebName  string // 必填
	FTP      bool
	Database bool
	Path     bool
}

ReqDeleteSite 删除网站 URI 地址:/site?action=DeleteSite

type ReqSiteBackups

type ReqSiteBackups struct {
	P      int64
	Limit  int64 // 必填
	Type   int64 // 必不填或填0
	ToJS   string
	Search int64 // 必填
}

ReqSiteBackups 获取网站备份列表 URI 地址:/data?action=getData&table=backup

type ReqSites

type ReqSites struct {
	P      int64
	Limit  int64 // 必填
	Type   int64
	Order  string
	ToJS   string
	Search string
}

ReqSites 获取网站列表 URI 地址:/data?action=getData&table=sites

type RespAddSite

type RespAddSite struct {
	FtpStatus      bool   `json:"ftpStatus"`
	DatabaseUser   string `json:"databaseUser"`
	DatabaseStatus bool   `json:"databaseStatus"`
	FtpUser        string `json:"ftpUser"`
	DatabasePass   string `json:"databasePass"`
	SiteStatus     bool   `json:"siteStatus"`
	FtpPass        string `json:"ftpPass"`
}

RespAddSite 创建网站 URI 地址:/site?action=AddSite

type RespGetFile

type RespGetFile struct {
	Status   bool   `json:"status"`
	Data     string `json:"data"`
	Encoding string `json:"encoding"`
}

RespGetFile 获取指定文件

type RespLimitNet

type RespLimitNet struct {
	LimitRate int `json:"limit_rate"`
	Perserver int `json:"perserver"`
	Perip     int `json:"perip"`
}

RespLimitNet 获取网络限制

type RespMSG

type RespMSG struct {
	Status bool   `json:"status"`
	Msg    string `json:"msg"`
}

RespMSG 通用消息结构

type RespSiteBackups

type RespSiteBackups struct {
	Data []struct {
		Name     string `json:"name"`
		Addtime  string `json:"addtime"`
		Pid      int    `json:"pid"`
		Filename string `json:"filename"`
		ID       int    `json:"id"`
		Size     int    `json:"size"`
	} `json:"data"`
	Where string `json:"where"`
	Page  string `json:"page"`
}

RespSiteBackups 获取网站备份列表 URI 地址:/data?action=getData&table=backup

type RespSites

type RespSites struct {
	Data []struct {
		Status      string `json:"status"`
		Ps          string `json:"ps"`
		Domain      int    `json:"domain"`
		Name        string `json:"name"`
		Addtime     string `json:"addtime"`
		Path        string `json:"path"`
		BackupCount int    `json:"backup_count"`
		Edate       string `json:"edate"`
		ID          int    `json:"id"`
	} `json:"data"`
	Where string `json:"where"`
	Page  string `json:"page"`
}

RespSites 获取网站列表 URI 地址:/data?action=getData&table=sites

type RespUserINI

type RespUserINI struct {
	Pass    bool `json:"pass"`
	Logs    bool `json:"logs"`
	Userini bool `json:"userini"`
	RunPath struct {
		Dirs    []string `json:"dirs"`
		RunPath string   `json:"runPath"`
	} `json:"runPath"`
}

type RewriteList

type RewriteList struct {
	Rewrites []string `json:"rewrite"`
}

RewriteList 伪静态可用列表

type SiteDomains

type SiteDomains []struct {
	Port    int    `json:"port"`
	Addtime string `json:"addtime"`
	Pid     int    `json:"pid"`
	ID      int    `json:"id"`
	Name    string `json:"name"`
}

SiteDomains 获取网站的域名列表 URI 地址:/data?action=getData&table=domain

type SiteTypes

type SiteTypes []struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

SiteTypes 获取网站分类 URI 地址:/site?action=get_site_types

type SystemTotal

type SystemTotal struct {
	CPURealUsed float64 `json:"cpuRealUsed"` // cpu使用率(百分比)
	MemTotal    int     `json:"memTotal"`    // 物理内存容量(MB)
	System      string  `json:"system"`      // 操作系统信息
	MemRealUsed int     `json:"memRealUsed"` // 物已使用的物理内存 (MB)
	CPUNum      int     `json:"cpuNum"`      // CPU 核心数
	MemFree     int     `json:"memFree"`     // 可用物理内存
	Version     string  `json:"version"`     // 面板版本
	Time        string  `json:"time"`        // 上次开机到现在的运行时间
	MemCached   int     `json:"memCached"`   // 缓存化的内存
	MemBuffers  int     `json:"memBuffers"`  // 系统缓冲 (MB)
	Isuser      int     `json:"isuser"`      // ?
}

SystemTotal 获取系统基础统计 URI 地址:/system?action=GetSystemTotal

type UpdateStatus

type UpdateStatus struct {
	Status    bool   `json:"status"`
	Version   string `json:"version"`
	UpdateMsg string `json:"updateMsg"`
}

UpdateStatus 检查面板更新 URI 地址:/ajax?action=UpdatePanel

Jump to

Keyboard shortcuts

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