This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from rootphantomer/dev
v1.1
- Loading branch information
Showing
6 changed files
with
107 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode/ | ||
quake_go | ||
quake | ||
quake | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
module quake | ||
|
||
go 1.19 | ||
|
||
require gopkg.in/yaml.v2 v2.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* @Author: ph4nt0mer [email protected] | ||
* @Date: 2022-09-06 10:04:23 | ||
* @LastEditors: ph4nt0mer | ||
* @LastEditTime: 2022-09-06 11:17:07 | ||
* @FilePath: /quake_go/src/utils/YamlAction.go | ||
* @Description:读写yaml | ||
* | ||
* Copyright (c) 2022 by ph4nt0mer, All Rights Reserved. | ||
*/ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type TokenInfo struct { | ||
Token string `yaml:"token"` | ||
} | ||
|
||
func WriteYaml(path string, token string) { | ||
// 进行写yaml操作 | ||
var tokeninfo TokenInfo | ||
tokeninfo.Token = token | ||
data, err := yaml.Marshal(tokeninfo) | ||
//config赋值777操作 | ||
err = ioutil.WriteFile(path, data, 0777) | ||
if err = ioutil.WriteFile(path, data, 0777); err != nil { | ||
fmt.Printf("token init fail!") | ||
} else { | ||
fmt.Printf("token init success!") | ||
} | ||
|
||
} | ||
|
||
func checkError(err error) bool { | ||
// 判断是否有错误,有错误nil,返回false,无返回true | ||
if err != nil { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
func ReadYaml(path string) (TokenInfo, bool) { | ||
// 读取yaml里面的内容 | ||
content, err := ioutil.ReadFile(path) | ||
status := checkError(err) | ||
var token TokenInfo | ||
err = yaml.Unmarshal(content, &token) | ||
status = checkError(err) | ||
return token, status | ||
} |