Skip to content

Commit

Permalink
golint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Mar 5, 2020
1 parent 3342487 commit ec3e3c9
Show file tree
Hide file tree
Showing 25 changed files with 65 additions and 201 deletions.
15 changes: 0 additions & 15 deletions cmd/add.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/completion.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/del.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/restart.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/start.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/status.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/stop.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/tls.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
15 changes: 0 additions & 15 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand Down
16 changes: 1 addition & 15 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
/*
Copyright © 2020 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
Expand All @@ -23,6 +8,7 @@ import (
)

var (
// Version
Version string
BuildDate string
GoVersion string
Expand Down
4 changes: 4 additions & 0 deletions core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,27 @@ import (
"io/ioutil"
)

// ClientConfig 结构体
type ClientConfig struct {
Config
SSl ClientSSL `json:"ssl"`
Tcp ClientTCP `json:"tcp"`
}

// ClientSSL 结构体
type ClientSSL struct {
SSL
Verify bool `json:"verify"`
VerifyHostname bool `json:"verify_hostname"`
Sni string `json:"sni"`
}

// ClientTCP 结构体
type ClientTCP struct {
TCP
}

// WriteClient 生成客户端json
func WriteClient(password string, domain string, writePath string) bool {
box := packr.New("client.json", "../asset")
data, err := box.Find("client.json")
Expand Down
3 changes: 3 additions & 0 deletions core/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

var dbPath = "/var/lib/trojan-manager"

// GetValue 获取leveldb值
func GetValue(key string) (string, error) {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
Expand All @@ -19,6 +20,7 @@ func GetValue(key string) (string, error) {
return string(result), nil
}

// SetValue 设置leveldb值
func SetValue(key string, value string) error {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
Expand All @@ -28,6 +30,7 @@ func SetValue(key string, value string) error {
return db.Put([]byte(key), []byte(value), nil)
}

// DelValue 删除值
func DelValue(key string) error {
db, err := leveldb.OpenFile(dbPath, nil)
defer db.Close()
Expand Down
10 changes: 10 additions & 0 deletions core/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"crypto/sha256"
"database/sql"
"fmt"
// mysql sql驱动
_ "github.com/go-sql-driver/mysql"
"strconv"
"strings"
)

// Mysql 结构体
type Mysql struct {
Enabled bool `json:"enabled"`
ServerAddr string `json:"server_addr"`
Expand All @@ -18,6 +20,7 @@ type Mysql struct {
Password string `json:"password"`
}

// User 用户表记录结构体
type User struct {
ID uint
Username string
Expand All @@ -27,6 +30,7 @@ type User struct {
Upload uint64
}

// GetDB 获取mysql数据库连接
func (mysql *Mysql) GetDB() *sql.DB {
conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", mysql.Username, mysql.Password, mysql.ServerAddr, mysql.ServerPort, mysql.Database)
db, err := sql.Open("mysql", conn)
Expand All @@ -37,6 +41,7 @@ func (mysql *Mysql) GetDB() *sql.DB {
return db
}

// CreateTable 不存在trojan user表则自动创建
func (mysql *Mysql) CreateTable() {
db := mysql.GetDB()
defer db.Close()
Expand All @@ -56,6 +61,7 @@ CREATE TABLE IF NOT EXISTS users (
}
}

// CreateUser 创建Trojan用户
func (mysql *Mysql) CreateUser(username string, password string) error {
db := mysql.GetDB()
defer db.Close()
Expand All @@ -71,6 +77,7 @@ func (mysql *Mysql) CreateUser(username string, password string) error {
return nil
}

// DeleteUser 删除用户
func (mysql *Mysql) DeleteUser(id uint) error {
db := mysql.GetDB()
defer db.Close()
Expand All @@ -83,6 +90,7 @@ func (mysql *Mysql) DeleteUser(id uint) error {
return nil
}

// SetQuota 限制流量
func (mysql *Mysql) SetQuota(id uint, quota int) error {
db := mysql.GetDB()
defer db.Close()
Expand All @@ -93,6 +101,7 @@ func (mysql *Mysql) SetQuota(id uint, quota int) error {
return nil
}

// CleanData 清空流量统计
func (mysql *Mysql) CleanData(id uint) error {
db := mysql.GetDB()
defer db.Close()
Expand All @@ -103,6 +112,7 @@ func (mysql *Mysql) CleanData(id uint) error {
return nil
}

// GetData 获取用户记录
func (mysql *Mysql) GetData(ids ...string) *[]User {
var dataList []User
querySQL := "SELECT * FROM users"
Expand Down
Loading

0 comments on commit ec3e3c9

Please sign in to comment.