glbm

package module
v1.6.16 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

README

glbm

介绍

glbm的全称是(Go Linux Basic module), 即使用Golang编写的Linux基础模块

Gitee 项目地址

特色

  • 使用全中文注释,即使小白也能轻松上手
  • 完全开源、永久免费

功能清单

详细功能清单请访问pkg.go.Dev

安装

关闭校验

设置环境变量

export GOSUMDB="off"
开始安装

首先进入你的项目根目录,然后执行下面的命令

go get -u gitee.com/liumou_site/glbm

效果如下

➜  go get -u gitee.com/liumou_site/glbm
go: downloading gitee.com/liumou_site/glbm v1.3.4
go: gitee.com/liumou_site/glbm upgrade => v1.3.4
go: downloading gitee.com/liumou_site/gcs v1.2.3
go: downloading gitee.com/liumou_site/logger v1.1.1
go: downloading github.com/spf13/cast v1.5.0
➜  demo

使用

Demo

最终请看单元测试案例

其他演示
package main

import (
	"fmt"
	"gitee.com/liumou_site/glbm"
)

// Ju 权限验证
func Ju() {
	g := glbm.CheckSudo("1")
	if g {
		fmt.Println("密码检验正确")
	} else {
		fmt.Println("密码错误或无权限")
	}
	d := glbm.Developer()
	if d {
		fmt.Println("已开启开发者")
	} else {
		fmt.Println("未开启开发者")
	}
}

// GetUser 获取用户信息
func GetUser() {
	get, username, uid, uHome := glbm.GetUserInfo(false)
	if get {
		fmt.Println(username)
		fmt.Println(uid)
		fmt.Println(uHome)
	}
}

// OsInfo 获取系统信息
func OsInfo() {
	osType, osArch, ov, err := glbm.GetOsInfo()
	if err != nil{
		fmt.Println("获取失败")
    }else{
		fmt.Println(osType)
		fmt.Println(osArch)
		fmt.Println(ov)
		GetUser()
    }
}

问题反馈

点击链接加入QQ群聊【坐公交也用券

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckSudo

func CheckSudo(password string) bool

CheckSudo 判断是否拥有sudo权限

func CurlToSave

func CurlToSave(url, filename string, cover bool) bool

CurlToSave 使用Curl下载文件到指定路径(cover是否覆盖已有文件)

func Developer

func Developer() bool

Developer UOS系统下检查是否开启开发者模式

func GetUserInfo

func GetUserInfo() (*user.User, error)

GetUserInfo 获取当前系统环境信息(display: 是否显示信息)

func IsDockerDevice

func IsDockerDevice(eth string) bool

IsDockerDevice 判断是否Docker网卡

func IsIPv4

func IsIPv4(ipAddr string) bool

IsIPv4 判断是否属于IPv4

func IsLoopbackV4

func IsLoopbackV4(ipAddr string) bool

IsLoopbackV4 判断是否属于回环

func Version

func Version() string

func WgetToSave

func WgetToSave(url, filename string) bool

WgetToSave 使用wget下载文件到指定路径

Types

type ApiApt

type ApiApt struct {
	Sudo *gcs.ApiSudo // 执行sudo命令
	Err  error        // 错误信息

	Debug bool // 是否开启Debug
	Info  bool // 是否开启Info
	// contains filtered or unexported fields
}

ApiApt 定义一个命令行密码结构体

func NewApt

func NewApt(password string, debug, realtime bool) *ApiApt

NewApt 管理初始化

func (*ApiApt) AptLocalInstallFile

func (api *ApiApt) AptLocalInstallFile(filename, name string) (err error)

AptLocalInstallFile 使用apt安装本地文件(单个),安装之前将会检测文件是否存在

func (*ApiApt) AptLocalInstallStr

func (api *ApiApt) AptLocalInstallStr(installStr, name string) bool

AptLocalInstallStr 使用apt安装本地文件(字符串),直接安装,不会检测文件是否存在

func (*ApiApt) Install

func (api *ApiApt) Install(Package string) bool

Install 使用apt在线安装包

func (*ApiApt) InstallList

func (api *ApiApt) InstallList(pacList list.List) (ok, failed list.List)

InstallList 通过apt安装包(列表传入)

func (*ApiApt) InstallSlice

func (api *ApiApt) InstallSlice(pacList []string) (ok, failed list.List)

InstallSlice 通过apt安装包(切片传入) - 推荐

func (*ApiApt) LocalInstallList

func (api *ApiApt) LocalInstallList(fileList []string, name string) bool

LocalInstallList 使用apt安装本地文件(列表传入)

func (*ApiApt) Uninstall

func (api *ApiApt) Uninstall(Package string, name string) (res bool)

Uninstall 通过apt卸载单个包

func (*ApiApt) UninstallList

func (api *ApiApt) UninstallList(pacList list.List) (ok, failed list.List)

UninstallList 通过apt卸载包(列表传入)

func (*ApiApt) UninstallSlice

func (api *ApiApt) UninstallSlice(pacList []string) (ok, failed list.List)

UninstallSlice 通过apt卸载包(列表传入)

func (*ApiApt) UpdateIndex

func (api *ApiApt) UpdateIndex() (res bool)

UpdateIndex 更新索引

func (*ApiApt) Upgrade

func (api *ApiApt) Upgrade() (res bool)

Upgrade 更新系统

type ApiConnection

type ApiConnection struct {
	Name   string // 连接名称(例如: dhcp)
	Types  string // 连接类型(bridge/wifi/ethernet)
	Method string // 连接模式(auto)

	Dns     []string // DNS列表
	Dev     string   // 设备名称
	Gw      net.IP   // 网关地址
	Address net.IP   // IP地址
	Mask    int      // 子网掩码
	Err     error    // 错误信息

	UseConName string   // 正在使用的连接名称
	ConList    []string // 连接列表
	// contains filtered or unexported fields
}

ApiConnection 网络连接管理结构

func NewConnect

func NewConnect(debug bool) *ApiConnection

NewConnect 连接管理

func (*ApiConnection) AddConnect

func (c *ApiConnection) AddConnect() error

AddConnect 新增连接

func (*ApiConnection) AddDns

func (c *ApiConnection) AddDns() (err error)

AddDns 增加DNS,默认(119.29.29.29 180.76.76.76)

func (*ApiConnection) GetConDnsList

func (c *ApiConnection) GetConDnsList(con string)

GetConDnsList 获取一个连接配置的DNS服务器列表

func (*ApiConnection) GetConList

func (c *ApiConnection) GetConList()

GetConList 获取所有连接配置

func (*ApiConnection) GetUseCon

func (c *ApiConnection) GetUseCon()

GetUseCon 获取正在使用的连接配置

type ApiDpkg

type ApiDpkg struct {
	Sudo   *gcs.ApiSudo // 执行sudo命令
	Err    error        // 错误信息
	Result bool         // 操作结果
	Debug  bool         // 是否开启Debug
	Info   bool         // 是否开启Info
	// contains filtered or unexported fields
}

ApiDpkg 定义一个Dpkg管理结构

func NewDpkg

func NewDpkg(password string, realtime bool) *ApiDpkg

NewDpkg 初始化(realtime: 是否开启实时刷新)

func (*ApiDpkg) CheckPacKey

func (api *ApiDpkg) CheckPacKey(pac1, pac2 string) (bool, string)

CheckPacKey 使用两个关键词查询本地是否已安装某个软件包并返回最终包名

func (*ApiDpkg) CheckVersion

func (api *ApiDpkg) CheckVersion(pac string, version string) (status_ bool, ver_ string)

CheckVersion 使用dpkg检查本地安装版本与标准版本是否一致

func (*ApiDpkg) ConfigureAll

func (api *ApiDpkg) ConfigureAll() bool

ConfigureAll 使用 Dpkg --configure -a继续配置

func (*ApiDpkg) GetPackageStatus

func (api *ApiDpkg) GetPackageStatus(pacPackage string) (m map[string]string)

GetPackageStatus 使用 Dpkg查询包状态, 通过res返回字典,通过status返回查询状态,字典key(status/Name/version)

func (*ApiDpkg) InstallFile

func (api *ApiDpkg) InstallFile(pac string, name string)

InstallFile 使用 Dpkg安装本地文件

func (*ApiDpkg) InstallListLocal

func (api *ApiDpkg) InstallListLocal(fileList []string, name string)

InstallListLocal 使用 Dpkg安装本地文件(列表传入)

func (*ApiDpkg) Installed

func (api *ApiDpkg) Installed(pac string) bool

Installed 使用Dpkg查询是否已安装(ii)

func (*ApiDpkg) Uninstall

func (api *ApiDpkg) Uninstall(Package string)

Uninstall 使用 Dpkg卸载单个包

func (*ApiDpkg) UninstallSlice

func (api *ApiDpkg) UninstallSlice(pacList []string)

UninstallSlice 使用 Dpkg卸载包(切片传入)

type ApiEth

type ApiEth struct {
	Index int    // 网卡设备索引
	Name  string // 网卡名称
	Ipv4  net.IP // IPV4地址
	Mask  int    //子网掩码
	Mac   string // Mac物理地址
	Err   error  // 错误信息
}

ApiEth 网卡信息结构体

type ApiFile

type ApiFile struct {
	PathAbs    string // 操作对象绝对路径
	PathBase   string // 操作对象基础文件名
	PathFormat string // 操作对象文件格式
	Src        string // 源文件
	SrcAbs     string // 源文件绝对路径
	SrcBase    string // 源文件基础文件名
	SrcFormat  string // 源文件格式
	Dst        string // 目标文件
	DstAbs     string // 目标文件绝对路径
	DstBase    string // 目标文件基础文件名
	DstFormat  string // 目标文件格式

	Err error // 错误
	// contains filtered or unexported fields
}

ApiFile 文件管理

func NewFile

func NewFile(src string) *ApiFile

NewFile 文件管理模块

func (*ApiFile) Copy

func (api *ApiFile) Copy(dst string) *ApiFile

Copy 复制文件/文件夹

func (*ApiFile) Delete

func (api *ApiFile) Delete() *ApiFile

Delete 删除文件/文件夹,默认使用Src文件

func (*ApiFile) DeleteFile

func (api *ApiFile) DeleteFile() *ApiFile

DeleteFile 删除文件,默认使用Src文件

func (*ApiFile) Move

func (api *ApiFile) Move(dst string) *ApiFile

Move 移动文件/文件夹

type ApiFileSudo

type ApiFileSudo struct {
	Password string // 密码

	ApiFile // 继承文件结构
	// contains filtered or unexported fields
}

ApiFileSudo 文件管理(超级权限)

func NewFileSudo

func NewFileSudo(src, password string) *ApiFileSudo

NewFileSudo 文件管理模块

func (*ApiFileSudo) CopySudo

func (api *ApiFileSudo) CopySudo(dst string) *ApiFileSudo

CopySudo 使用Sudo权限复制文件/文件夹

func (*ApiFileSudo) DeleteFileSudo

func (api *ApiFileSudo) DeleteFileSudo(filename string) *ApiFileSudo

DeleteFileSudo 使用Sudo权限删除文件

func (*ApiFileSudo) DeleteSudo

func (api *ApiFileSudo) DeleteSudo(filename string) *ApiFileSudo

DeleteSudo 使用Sudo权限删除文件/文件夹

func (*ApiFileSudo) MoveSudo

func (api *ApiFileSudo) MoveSudo(dst string) *ApiFileSudo

MoveSudo 使用Sudo权限移动文件/文件夹

type ApiNmcli

type ApiNmcli struct {
	DefaultGw      net.IP // 当前默认网关
	DefaultDevices string // 当前默认网卡设备

	Err error // 错误信息
	// contains filtered or unexported fields
}

ApiNmcli 网卡管理

func NewNmcli

func NewNmcli() *ApiNmcli

NewNmcli 返回一个网卡管理实例

func (*ApiNmcli) GetAllEthInfo

func (n *ApiNmcli) GetAllEthInfo() ([]ApiEth, error)

GetAllEthInfo 获取所有网卡信息(IPV4)

func (*ApiNmcli) GetConnectionList

func (n *ApiNmcli) GetConnectionList() bool

GetConnectionList 获取指定设备及类型的连接列表

func (*ApiNmcli) GetDefaultRouteInfo

func (n *ApiNmcli) GetDefaultRouteInfo() error

GetDefaultRouteInfo 获取默认网关&网卡设备

func (*ApiNmcli) GetEthGw

func (n *ApiNmcli) GetEthGw(eth string) (net.IP, error)

GetEthGw 获取指定网卡的网关地址

func (*ApiNmcli) GetEthInfo

func (n *ApiNmcli) GetEthInfo(eth string) (EthInfo, error)

GetEthInfo 获取指定网卡的网络信息

type ApiService

type ApiService struct {
	Name     string // 服务名称
	Err      error  // 错误
	Status   string // 当前状态
	Password string // Sudo权限密码
	// contains filtered or unexported fields
}

ApiService 服务管理结构

func NewService

func NewService(name, password string) *ApiService

func (*ApiService) Disable

func (api *ApiService) Disable() *ApiService

func (*ApiService) Enable

func (api *ApiService) Enable() *ApiService

func (*ApiService) Exists

func (api *ApiService) Exists() bool

func (*ApiService) ReLoad

func (api *ApiService) ReLoad() *ApiService

func (*ApiService) ReLoadDaemon

func (api *ApiService) ReLoadDaemon() *ApiService

func (*ApiService) ReStart

func (api *ApiService) ReStart()

func (*ApiService) Start

func (api *ApiService) Start()

func (*ApiService) Stop

func (api *ApiService) Stop()

type EthInfo

type EthInfo struct {
	IP   net.IP   // IP地址
	GW   net.IP   // 网关地址
	MASK int      // 子网掩码
	DNS  []net.IP // DNS列表
}

EthInfo 网卡信息结构

type OsInfo added in v1.6.16

type OsInfo struct {
	Name     string // 系统名称
	Version  string // 系统版本
	CodeName string // 系统代号
	Arch     string // 系统架构
}

OsInfo 系统信息结构

func GetOsInfo

func GetOsInfo() (info *OsInfo, err error)

GetOsInfo 获取系统信息

type UserInfo added in v1.6.16

type UserInfo struct {
	Name string // 用户名称
	Home string // 用户主目录
	UID  string // 用户UID
	Arch string // 系统架构
}

UserInfo 用户信息结构

Jump to

Keyboard shortcuts

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