go3xui is a Go client library for interacting with the 3x-ui panel via its API. The project is currently under active development and does not yet cover the full functionality of the panel.
At this stage, the library supports client-related operations, including the following methods.
GetTrafficsByEmail— retrieve detailed information about a client by email (includes traffic statistics and related data)GetTrafficsByID— retrieve detailed information about a client by UUIDGetIpsByEmail— fetch the IP history associated with a client by emailAdd— add a new client to a specific inbound by its IDUpdate— update an existing client identified by UUID within a specific inboundDelete— delete a client by UUID and inbound IDOnline— get IDs of currently online usersResetStats— reset the IP history associated with a client by email
The goal of the project is to provide a clean, safe, and convenient interface for automating the management of 3x-ui.
Pull requests and feedback are welcome!
package main
import (
"context"
"fmt"
"go3xui/pkg/api"
"go3xui/pkg/model"
"go3xui/pkg/utils"
"time"
)
var cfg = api.ConnectionConfig{
Host: "http://127.0.0.1:2053/admin",
Username: "test",
Password: "test",
}
func Login() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
return a.Login(context.Background(), "")
}
func GetTrafficsByEmail() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
if traffic, err := client.GetTrafficsByEmail(context.Background(), "test"); err != nil {
return err
} else {
fmt.Println(traffic)
}
return nil
}
func GetTrafficsByID() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
if traffic, err := client.GetTrafficsByID(context.Background(), "bbfad557-28f2-47e5-9f3d-e3c7f532fbda"); err != nil {
return err
} else {
fmt.Println(traffic)
}
return nil
}
func Add() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
cl := []*model.Client{{
Flow: utils.FlowVision,
Email: "dp1plmlt89",
Id: "bbfad557-28f2-47e5-9f3d-e3c7f532fbda",
Enable: false,
SubId: "2rv0gb458kbfl532",
ExpiryTime: time.Now().Add(time.Hour * 24 * 5).UnixMilli(),
}}
return client.Add(context.Background(), 1, cl)
}
func Update() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
cl := model.Client{
Flow: utils.FlowVision,
Email: "dp1plmlt89",
Id: "bbfad557-28f2-47e5-9f3d-e3c7f532fbda",
Enable: true,
SubId: "2rv0gb458kbfl532",
ExpiryTime: time.Now().Add(time.Hour * 24 * 5).UnixMilli(),
}
return client.Update(context.Background(), 1, &cl)
}
func Delete() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
return client.Delete(context.Background(), 1, "bbfad557-28f2-47e5-9f3d-e3c7f532fbda")
}
func Online() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
_, err = client.Online(context.Background())
return err
}
func ResetIps() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
return client.ResetIps(context.Background(), "test")
}
func ResetStats() error {
a, err := api.NewBaseApi(cfg)
if err != nil {
return err
}
err = a.Login(context.Background(), "")
if err != nil {
return err
}
client := api.NewClientApi(a)
return client.ResetIps(context.Background(), "test")
}
func main() {
_ = Login()
_ = GetTrafficsByEmail()
_ = Delete()
_ = Add()
_ = Update()
_ = Online()
_ = ResetIps()
_ = ResetStats()
}- Full API coverage for 3x-ui
- High-level wrappers for common operations
If you find this project useful and want to support its development:
- TON (Toncoin):
UQBaeaCSvLpG2xKdzQQem8j1oqTU-Zimrn8z9p1Lw-wsraU2 - USDT (TRC20):
TCEHVwRweaEyy9kGTYR5g6Rgy66CxiP6Uj - Bitcoin (BTC):
1CCyT6HKvK8P3Dwjb8i59nzyBbf3GpjVyx
Thank you for your support 🙏