Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions internal/cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func runUserCreate(cfg *config.CLIConfig) error {
if err != nil {
return err
}
defer gitlabClient.CloseIdleConnections()

userConfig, err := config.Load(cfg.ConfigFile)
if err != nil {
Expand Down Expand Up @@ -210,6 +211,7 @@ func runUserCleanup(cfg *config.CLIConfig) error {
if err != nil {
return err
}
defer gitlabClient.CloseIdleConnections()

userConfig, err := config.Load(cfg.ConfigFile)
if err != nil {
Expand Down Expand Up @@ -258,6 +260,7 @@ func runUserDelete(cfg *config.CLIConfig, usernames string) error {
if err != nil {
return err
}
defer gitlabClient.CloseIdleConnections()

// 解析用户名列表(以逗号分隔)
usernameList := strings.Split(usernames, ",")
Expand Down Expand Up @@ -354,6 +357,7 @@ func runUserList(cfg *config.CLIConfig, searchPrefix string) error {
if err != nil {
return err
}
defer gitlabClient.CloseIdleConnections()

log.Printf("\n正在获取用户列表...\n")
if searchPrefix != "" {
Expand Down Expand Up @@ -382,6 +386,7 @@ func runUserDeleteByPrefix(cfg *config.CLIConfig, prefix string, dryRun bool) er
if err != nil {
return err
}
defer gitlabClient.CloseIdleConnections()

log.Printf("\n正在搜索用户名以 '%s' 开头的用户...\n", prefix)

Expand Down
5 changes: 5 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func NewGitLabClient(host, token string) (*GitLabClient, error) {
}, nil
}

// CloseIdleConnections 关闭空闲连接,防止程序退出时卡住
func (c *GitLabClient) CloseIdleConnections() {
c.client.HTTPClient().CloseIdleConnections()
}

// CheckAuth 检查认证和管理员权限
func (c *GitLabClient) CheckAuth() error {
user, _, err := c.client.Users.CurrentUser()
Expand Down
Loading