generated from bing/readnotes
feat 不知道改了什么
This commit is contained in:
parent
4e392e9746
commit
dc9d8b6e94
20
demo/main.go
20
demo/main.go
|
@ -3,12 +3,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"net/http"
|
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func get(resp http.ResponseWriter, req *http.Request){
|
func get(resp http.ResponseWriter, req *http.Request) {
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Write([]byte(fmt.Sprintf("get hostname error:%v", err)))
|
resp.Write([]byte(fmt.Sprintf("get hostname error:%v", err)))
|
||||||
|
@ -20,14 +20,14 @@ func get(resp http.ResponseWriter, req *http.Request){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
addrString := ""
|
addrString := ""
|
||||||
for _, addr := range addrs{
|
for _, addr := range addrs {
|
||||||
addrString += " " + addr.String()
|
addrString += " " + addr.String()
|
||||||
}
|
}
|
||||||
resp.Write([]byte(fmt.Sprintf("response from host: %s, ip is:%s", hostname, addrString)))
|
resp.Write([]byte(fmt.Sprintf("response from host: %s, ip is:%s", hostname, addrString)))
|
||||||
}
|
}
|
||||||
|
|
||||||
//read the file which path is "/data/test.txt"
|
// read the file which path is "/data/test.txt"
|
||||||
func readFile(resp http.ResponseWriter, req *http.Request){
|
func readFile(resp http.ResponseWriter, req *http.Request) {
|
||||||
file, err := os.Open("/data/test.txt")
|
file, err := os.Open("/data/test.txt")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Write([]byte(fmt.Sprintf("open /data/test.txt error:%v", err)))
|
resp.Write([]byte(fmt.Sprintf("open /data/test.txt error:%v", err)))
|
||||||
|
@ -43,8 +43,8 @@ func readFile(resp http.ResponseWriter, req *http.Request){
|
||||||
resp.Write(data[0:n])
|
resp.Write(data[0:n])
|
||||||
}
|
}
|
||||||
|
|
||||||
//write a string to the file
|
// write a string to the file
|
||||||
func writeFile(resp http.ResponseWriter, req *http.Request){
|
func writeFile(resp http.ResponseWriter, req *http.Request) {
|
||||||
file, err := os.OpenFile("/data/test.txt", os.O_RDWR|os.O_APPEND, os.ModePerm)
|
file, err := os.OpenFile("/data/test.txt", os.O_RDWR|os.O_APPEND, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resp.Write([]byte(fmt.Sprintf("open /data/test.txt error:%v", err)))
|
resp.Write([]byte(fmt.Sprintf("open /data/test.txt error:%v", err)))
|
||||||
|
@ -60,7 +60,7 @@ func writeFile(resp http.ResponseWriter, req *http.Request){
|
||||||
resp.Write([]byte("write file successed."))
|
resp.Write([]byte("write file successed."))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main (){
|
func main() {
|
||||||
router := http.DefaultServeMux
|
router := http.DefaultServeMux
|
||||||
router.HandleFunc("/", get)
|
router.HandleFunc("/", get)
|
||||||
router.HandleFunc("/read", readFile)
|
router.HandleFunc("/read", readFile)
|
||||||
|
@ -70,4 +70,4 @@ func main (){
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,28 +6,27 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
func main(){
|
|
||||||
cmd := cobra.Command{
|
cmd := cobra.Command{
|
||||||
Use: "cobra",
|
Use: "cobra",
|
||||||
Short: "this is a cobra demo",
|
Short: "this is a cobra demo",
|
||||||
Run: func(cmd *cobra.Command, args []string){
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("good! you run a cobra command!")
|
fmt.Println("good! you run a cobra command!")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var newLine *bool
|
var newLine *bool
|
||||||
subCmd := cobra.Command{
|
subCmd := cobra.Command{
|
||||||
Use: "echo",
|
Use: "echo",
|
||||||
Short: "echo your input",
|
Short: "echo your input",
|
||||||
Run: func(cmd *cobra.Command, args []string){
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if newLine != nil && *newLine{
|
if newLine != nil && *newLine {
|
||||||
fmt.Println(arg)
|
fmt.Println(arg)
|
||||||
}else{
|
} else {
|
||||||
fmt.Printf("%s ", arg)
|
fmt.Printf("%s ", arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if newLine == nil || ! *newLine{
|
if newLine == nil || !*newLine {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -36,4 +35,4 @@ func main(){
|
||||||
|
|
||||||
cmd.AddCommand(&subCmd)
|
cmd.AddCommand(&subCmd)
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,25 +8,40 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
RedMax = 33
|
RedMax = 33
|
||||||
BlueMax = 16
|
BlueMax = 16
|
||||||
)
|
)
|
||||||
|
|
||||||
func randRate(){
|
type ball struct{
|
||||||
rand.Seed(time.Now().UnixNano())
|
B int
|
||||||
rate := rand.Intn(100) + 1
|
R []int
|
||||||
fmt.Printf("\t (中奖概率%d%%)", rate)
|
Rate int
|
||||||
}
|
}
|
||||||
|
|
||||||
func randBall(max int)int{
|
func (b ball)display(){
|
||||||
rand.Seed(time.Now().UnixNano())
|
for _, r := range b.R {
|
||||||
return rand.Intn(max) + 1
|
fmt.Printf("\033[1;31;40m%d\033[0m \t", r)
|
||||||
|
}
|
||||||
|
fmt.Printf("\033[1;34;40m%d\033[0m \t", b.B)
|
||||||
|
fmt.Printf("\t (中奖概率%d%%)\n", b.Rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isIn(list []int, item int )bool{
|
func randRate() int {
|
||||||
for _, i := range list{
|
src := rand.NewSource(time.Now().UnixNano())
|
||||||
|
rd := rand.New(src)
|
||||||
|
rate := rd.Intn(100) + 1
|
||||||
|
return rate
|
||||||
|
}
|
||||||
|
|
||||||
|
func randBall(max int) int {
|
||||||
|
src := rand.NewSource(time.Now().UnixNano())
|
||||||
|
rd := rand.New(src)
|
||||||
|
return rd.Intn(max) + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func isIn(list []int, item int) bool {
|
||||||
|
for _, i := range list {
|
||||||
if i == item {
|
if i == item {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -34,35 +49,46 @@ func isIn(list []int, item int )bool{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func randDoubleBall(){
|
func randDoubleBall()ball{
|
||||||
balls := []int{}
|
b := ball{}
|
||||||
for i := 0; i < 6;{
|
for i := 0; i < 6; {
|
||||||
ball := randBall(RedMax)
|
r := randBall(RedMax)
|
||||||
if isIn(balls, ball) {
|
if isIn(b.R, r) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
balls = append(balls, ball)
|
b.R = append(b.R, r)
|
||||||
}
|
}
|
||||||
sort.Ints(balls)
|
sort.Ints(b.R)
|
||||||
blueball := randBall(BlueMax)
|
b.B = randBall(BlueMax)
|
||||||
for _, ball := range balls {
|
b.Rate = randRate()
|
||||||
fmt.Printf("\033[1;31;40m%d\033[0m \t", ball)
|
return b
|
||||||
}
|
|
||||||
fmt.Printf("\033[1;34;40m%d\033[0m \t", blueball)
|
|
||||||
randRate()
|
|
||||||
fmt.Println("")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
var groups int
|
var groups int
|
||||||
flag.IntVar(&groups, "g", 1, "注数")
|
var zhong bool
|
||||||
|
flag.IntVar(&groups, "g", 0, "注数")
|
||||||
|
flag.BoolVar(&zhong, "z", true, "必中")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if groups < 0 {
|
if groups < 1 {
|
||||||
groups = 1
|
groups = 1
|
||||||
|
}else{
|
||||||
|
zhong = false
|
||||||
|
}
|
||||||
|
if zhong {
|
||||||
|
for {
|
||||||
|
b := randDoubleBall()
|
||||||
|
if b.Rate == 100 {
|
||||||
|
b.display()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("为您选取了 %d 注随机双色球,祝君中奖!\n", groups)
|
fmt.Printf("为您选取了 %d 注随机双色球,祝君中奖!\n", groups)
|
||||||
for i := 0; i < groups; i++ {
|
for i := 0; i < groups; i++ {
|
||||||
randDoubleBall()
|
b:=randDoubleBall()
|
||||||
|
b.display()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package font
|
package font
|
||||||
|
|
||||||
|
type Font struct {
|
||||||
|
|
||||||
type Font struct{
|
|
||||||
Head Head `json:"head"`
|
Head Head `json:"head"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package font
|
package font
|
||||||
|
|
||||||
type Head struct {
|
type Head struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
TableCount uint16 `json:"tableCount"`
|
TableCount uint16 `json:"tableCount"`
|
||||||
Tables []Table `json:"tables"`
|
Tables []Table `json:"tables"`
|
||||||
SearchRange uint16 `json:"searchRange"`
|
SearchRange uint16 `json:"searchRange"`
|
||||||
EntrySelector uint16 `json:"entrySelector"`
|
EntrySelector uint16 `json:"entrySelector"`
|
||||||
RangeShift uint16 `json:"rangeShift"`
|
RangeShift uint16 `json:"rangeShift"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@ package font
|
||||||
type Table struct {
|
type Table struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Sum uint32 `json:"sum"`
|
Sum uint32 `json:"sum"`
|
||||||
Offset uint32 `json:"offset"`
|
Offset uint32 `json:"offset"`
|
||||||
Length uint32 `json:"length"`
|
Length uint32 `json:"length"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,26 +86,25 @@ type NameTable struct {
|
||||||
Style string `json:"style"`
|
Style string `json:"style"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NameRecord struct {
|
||||||
type NameRecord struct{
|
Platform uint16
|
||||||
Platform uint16
|
|
||||||
PlatformSpecific uint16
|
PlatformSpecific uint16
|
||||||
Language uint16
|
Language uint16
|
||||||
Name uint16
|
Name uint16
|
||||||
|
Length uint16
|
||||||
|
Offset uint16
|
||||||
|
}
|
||||||
|
|
||||||
|
type LangTagRecord struct {
|
||||||
Length uint16
|
Length uint16
|
||||||
Offset uint16
|
Offset uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
type LangTagRecord struct{
|
type NameTableFormat struct {
|
||||||
Length uint16
|
Format uint16
|
||||||
Offset uint16
|
RecordsCount uint16
|
||||||
}
|
StringOffset uint16
|
||||||
|
NameRecords []NameRecord
|
||||||
type NameTableFormat struct{
|
LangTagCount uint16 //only ver 1, apple not support
|
||||||
Format uint16
|
|
||||||
RecordsCount uint16
|
|
||||||
StringOffset uint16
|
|
||||||
NameRecords []NameRecord
|
|
||||||
LangTagCount uint16 //only ver 1, apple not support
|
|
||||||
LangTagRecords []LangTagRecord //only ver 1, apple not support
|
LangTagRecords []LangTagRecord //only ver 1, apple not support
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readInt8(fp *os.File)(int8, error){
|
func readInt8(fp *os.File) (int8, error) {
|
||||||
buff := make([]byte, 1)
|
buff := make([]byte, 1)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -18,7 +18,7 @@ func readInt8(fp *os.File)(int8, error){
|
||||||
return n, binary.Read(reader, binary.LittleEndian, &n)
|
return n, binary.Read(reader, binary.LittleEndian, &n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInt16(fp *os.File)(int16, error){
|
func readInt16(fp *os.File) (int16, error) {
|
||||||
buff := make([]byte, 2)
|
buff := make([]byte, 2)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,7 +29,7 @@ func readInt16(fp *os.File)(int16, error){
|
||||||
return n, binary.Read(reader, binary.LittleEndian, &n)
|
return n, binary.Read(reader, binary.LittleEndian, &n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInt32(fp *os.File)(int32, error){
|
func readInt32(fp *os.File) (int32, error) {
|
||||||
buff := make([]byte, 4)
|
buff := make([]byte, 4)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -40,7 +40,7 @@ func readInt32(fp *os.File)(int32, error){
|
||||||
return n, binary.Read(reader, binary.LittleEndian, &n)
|
return n, binary.Read(reader, binary.LittleEndian, &n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readInt64(fp *os.File)(int64, error){
|
func readInt64(fp *os.File) (int64, error) {
|
||||||
buff := make([]byte, 8)
|
buff := make([]byte, 8)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,7 @@ func readInt64(fp *os.File)(int64, error){
|
||||||
return n, binary.Read(reader, binary.LittleEndian, &n)
|
return n, binary.Read(reader, binary.LittleEndian, &n)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readUint8(fp *os.File)(uint8, error){
|
func readUint8(fp *os.File) (uint8, error) {
|
||||||
buff := make([]byte, 1)
|
buff := make([]byte, 1)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,7 +60,7 @@ func readUint8(fp *os.File)(uint8, error){
|
||||||
return uint8(buff[0]), nil
|
return uint8(buff[0]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readUint16(fp *os.File)(uint16, error){
|
func readUint16(fp *os.File) (uint16, error) {
|
||||||
buff := make([]byte, 2)
|
buff := make([]byte, 2)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -69,7 +69,7 @@ func readUint16(fp *os.File)(uint16, error){
|
||||||
return binary.BigEndian.Uint16(buff), nil
|
return binary.BigEndian.Uint16(buff), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readUint32(fp *os.File)(uint32, error){
|
func readUint32(fp *os.File) (uint32, error) {
|
||||||
buff := make([]byte, 4)
|
buff := make([]byte, 4)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -78,7 +78,7 @@ func readUint32(fp *os.File)(uint32, error){
|
||||||
return binary.BigEndian.Uint32(buff), nil
|
return binary.BigEndian.Uint32(buff), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readUint64(fp *os.File)(uint64, error){
|
func readUint64(fp *os.File) (uint64, error) {
|
||||||
buff := make([]byte, 8)
|
buff := make([]byte, 8)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,7 +87,7 @@ func readUint64(fp *os.File)(uint64, error){
|
||||||
return binary.BigEndian.Uint64(buff), nil
|
return binary.BigEndian.Uint64(buff), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readString(fp *os.File, len int)(string, error){
|
func readString(fp *os.File, len int) (string, error) {
|
||||||
buff := make([]byte, len)
|
buff := make([]byte, len)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -96,7 +96,7 @@ func readString(fp *os.File, len int)(string, error){
|
||||||
return string(buff), nil
|
return string(buff), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readBytes(fp *os.File, len int)([]byte, error){
|
func readBytes(fp *os.File, len int) ([]byte, error) {
|
||||||
buff := make([]byte, len)
|
buff := make([]byte, len)
|
||||||
_, err := fp.Read(buff)
|
_, err := fp.Read(buff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -105,7 +105,7 @@ func readBytes(fp *os.File, len int)([]byte, error){
|
||||||
return buff, nil
|
return buff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFontSearchArgs(fp *os.File)([]uint16, error){
|
func readFontSearchArgs(fp *os.File) ([]uint16, error) {
|
||||||
ret := []uint16{}
|
ret := []uint16{}
|
||||||
arg1, err := readUint16(fp)
|
arg1, err := readUint16(fp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -125,17 +125,17 @@ func readFontSearchArgs(fp *os.File)([]uint16, error){
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type ftable struct{
|
type ftable struct {
|
||||||
Name string
|
Name string
|
||||||
Sum uint32
|
Sum uint32
|
||||||
Offset uint32
|
Offset uint32
|
||||||
Length uint32
|
Length uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFontTables(fp *os.File, tables uint16)([]ftable, error){
|
func readFontTables(fp *os.File, tables uint16) ([]ftable, error) {
|
||||||
ret := []ftable{}
|
ret := []ftable{}
|
||||||
for i := 0; i < int(tables); i++ {
|
for i := 0; i < int(tables); i++ {
|
||||||
t :=ftable{}
|
t := ftable{}
|
||||||
name, err := readString(fp, 4)
|
name, err := readString(fp, 4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
|
@ -161,12 +161,12 @@ func readFontTables(fp *os.File, tables uint16)([]ftable, error){
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readNameTable(fp *os.File, offset uint32, length uint32)([]byte, error){
|
func readNameTable(fp *os.File, offset uint32, length uint32) ([]byte, error) {
|
||||||
fp.Seek(int64(offset), 0)
|
fp.Seek(int64(offset), 0)
|
||||||
return readBytes(fp, int(length))
|
return readBytes(fp, int(length))
|
||||||
}
|
}
|
||||||
|
|
||||||
func readFont(file string)error{
|
func readFont(file string) error {
|
||||||
fp, err := os.OpenFile(file, os.O_RDONLY, os.ModePerm)
|
fp, err := os.OpenFile(file, os.O_RDONLY, os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -209,9 +209,9 @@ func readFont(file string)error{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
err := readFont("文鼎中黑.ttf")
|
err := readFont("文鼎中黑.ttf")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,14 +6,13 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func get(c *gin.Context) {
|
||||||
func get(c *gin.Context){
|
|
||||||
//c.ClientIP()
|
//c.ClientIP()
|
||||||
log.Println()
|
log.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
engine := gin.Default()
|
engine := gin.Default()
|
||||||
engine.GET("/", get)
|
engine.GET("/", get)
|
||||||
engine.Run("0.0.0.0:10000")
|
engine.Run("0.0.0.0:10000")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func show(file string) error {
|
||||||
|
|
||||||
func show(file string)error{
|
|
||||||
mp3File, err := id3v2.Open(file, id3v2.Options{Parse: true})
|
mp3File, err := id3v2.Open(file, id3v2.Options{Parse: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -24,10 +22,10 @@ func show(file string)error{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func set()*cobra.Command{
|
func set() *cobra.Command {
|
||||||
var artist, title, genre, year, version, album, file string
|
var artist, title, genre, year, version, album, file string
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "set",
|
Use: "set",
|
||||||
Short: "set [options] set mp3 file info",
|
Short: "set [options] set mp3 file info",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
mp3File, err := id3v2.Open(file, id3v2.Options{Parse: true})
|
mp3File, err := id3v2.Open(file, id3v2.Options{Parse: true})
|
||||||
|
@ -41,7 +39,7 @@ func set()*cobra.Command{
|
||||||
if title != "" {
|
if title != "" {
|
||||||
mp3File.SetTitle(title)
|
mp3File.SetTitle(title)
|
||||||
}
|
}
|
||||||
if album != ""{
|
if album != "" {
|
||||||
mp3File.SetAlbum(album)
|
mp3File.SetAlbum(album)
|
||||||
}
|
}
|
||||||
if genre != "" {
|
if genre != "" {
|
||||||
|
@ -70,15 +68,15 @@ func set()*cobra.Command{
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Short: "",
|
Short: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
showCmd := &cobra.Command{
|
showCmd := &cobra.Command{
|
||||||
Use: "show",
|
Use: "show",
|
||||||
Short: "show [file]",
|
Short: "show [file]",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
if err := show(args[0]); err != nil {
|
if err := show(args[0]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -87,4 +85,4 @@ func main(){
|
||||||
}
|
}
|
||||||
cmd.AddCommand(showCmd, set())
|
cmd.AddCommand(showCmd, set())
|
||||||
cmd.Execute()
|
cmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,24 +11,24 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
User string
|
User string
|
||||||
ID string
|
ID string
|
||||||
msgChan chan string
|
msgChan chan string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client)Write(msg string){
|
func (c *Client) Write(msg string) {
|
||||||
c.msgChan <- msg
|
c.msgChan <- msg
|
||||||
}
|
}
|
||||||
|
|
||||||
type NServer struct {
|
type NServer struct {
|
||||||
notifier *notify.Notifier
|
notifier *notify.Notifier
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
flusher http.Flusher
|
flusher http.Flusher
|
||||||
}
|
}
|
||||||
|
|
||||||
var ch = make(chan string)
|
var ch = make(chan string)
|
||||||
|
|
||||||
func (n *NServer)Get(c *gin.Context){
|
func (n *NServer) Get(c *gin.Context) {
|
||||||
user := c.Query("user")
|
user := c.Query("user")
|
||||||
id := c.Query("client")
|
id := c.Query("client")
|
||||||
if user == "" || id == "" {
|
if user == "" || id == "" {
|
||||||
|
@ -70,8 +70,8 @@ func (n *NServer)Get(c *gin.Context){
|
||||||
// time.Sleep(100*time.Second)
|
// time.Sleep(100*time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NServer)Run(){
|
func (n *NServer) Run() {
|
||||||
ticker := time.NewTicker(2*time.Second)
|
ticker := time.NewTicker(2 * time.Second)
|
||||||
for t := range ticker.C {
|
for t := range ticker.C {
|
||||||
str := fmt.Sprintf("data: %v\n\n", t.Format("2006-01-02 15:04:05"))
|
str := fmt.Sprintf("data: %v\n\n", t.Format("2006-01-02 15:04:05"))
|
||||||
fmt.Println("send data to n")
|
fmt.Println("send data to n")
|
||||||
|
@ -87,7 +87,7 @@ func (n *NServer)Run(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
n := NServer{
|
n := NServer{
|
||||||
notifier: notify.NewNotifier(),
|
notifier: notify.NewNotifier(),
|
||||||
}
|
}
|
||||||
|
@ -123,4 +123,4 @@ func main(){
|
||||||
// }
|
// }
|
||||||
// }()
|
// }()
|
||||||
// log.Fatal(http.ListenAndServe(":18000", nil))
|
// log.Fatal(http.ListenAndServe(":18000", nil))
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -11,12 +11,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Consumer struct {
|
type Consumer struct {
|
||||||
UserID string
|
UserID string
|
||||||
ClientID string
|
ClientID string
|
||||||
conn io.WriteCloser
|
conn io.WriteCloser
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsumer(c *gin.Context)(*Consumer, error){
|
func NewConsumer(c *gin.Context) (*Consumer, error) {
|
||||||
user := c.Query("user")
|
user := c.Query("user")
|
||||||
clientID := c.Query("client")
|
clientID := c.Query("client")
|
||||||
if clientID == "" {
|
if clientID == "" {
|
||||||
|
@ -27,15 +27,15 @@ func NewConsumer(c *gin.Context)(*Consumer, error){
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
consumer := Consumer{
|
consumer := Consumer{
|
||||||
UserID: user,
|
UserID: user,
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
}
|
}
|
||||||
useGzip := false
|
useGzip := false
|
||||||
if strings.Contains(c.GetHeader("Accept-Encoding"), "gzip") {
|
if strings.Contains(c.GetHeader("Accept-Encoding"), "gzip") {
|
||||||
useGzip = true
|
useGzip = true
|
||||||
}
|
}
|
||||||
|
|
||||||
err = consumer.init(useGzip)
|
err = consumer.init(useGzip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
conn.Close()
|
conn.Close()
|
||||||
|
@ -43,12 +43,12 @@ func NewConsumer(c *gin.Context)(*Consumer, error){
|
||||||
return &consumer, err
|
return &consumer, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer)Write(msg string)error{
|
func (c *Consumer) Write(msg string) error {
|
||||||
_, err := c.conn.Write([]byte(fmt.Sprintf("data: %s\n\n", msg)))
|
_, err := c.conn.Write([]byte(fmt.Sprintf("data: %s\n\n", msg)))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Consumer)init(gz bool)error{
|
func (c *Consumer) init(gz bool) error {
|
||||||
if err := c.Write("HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\n"); err != nil {
|
if err := c.Write("HTTP/1.1 200 OK\r\nContent-Type: text/event-stream\r\n"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,4 @@ func (c *Consumer)init(gz bool)error{
|
||||||
}
|
}
|
||||||
return c.Write("\r\n")
|
return c.Write("\r\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package notify
|
package notify
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
User string
|
User string
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,60 +8,60 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Notifier struct {
|
type Notifier struct {
|
||||||
Consumers map[string]*Consumer
|
Consumers map[string]*Consumer
|
||||||
userClients map[string][]string
|
userClients map[string][]string
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
consumerChan chan *Consumer
|
consumerChan chan *Consumer
|
||||||
messageChan chan Message
|
messageChan chan Message
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNotifier()*Notifier{
|
func NewNotifier() *Notifier {
|
||||||
return &Notifier{
|
return &Notifier{
|
||||||
Consumers: make(map[string]*Consumer),
|
Consumers: make(map[string]*Consumer),
|
||||||
lock: sync.Mutex{},
|
lock: sync.Mutex{},
|
||||||
consumerChan: make(chan *Consumer),
|
consumerChan: make(chan *Consumer),
|
||||||
messageChan: make(chan Message),
|
messageChan: make(chan Message),
|
||||||
userClients: map[string][]string{},
|
userClients: map[string][]string{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)AddConsumer(c *gin.Context)error{
|
func (n *Notifier) AddConsumer(c *gin.Context) error {
|
||||||
consumer, err := NewConsumer(c)
|
consumer, err := NewConsumer(c)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go func () {
|
go func() {
|
||||||
n.consumerChan <- consumer
|
n.consumerChan <- consumer
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)recieveMessage(ctx context.Context){
|
func (n *Notifier) recieveMessage(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
select{
|
select {
|
||||||
case <- ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case msg := <- n.messageChan:
|
case msg := <-n.messageChan:
|
||||||
n.notify(msg)
|
n.notify(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)notify(msg Message){
|
func (n *Notifier) notify(msg Message) {
|
||||||
n.lock.Lock()
|
n.lock.Lock()
|
||||||
defer n.lock.Unlock()
|
defer n.lock.Unlock()
|
||||||
clts, ok := n.userClients[msg.User];
|
clts, ok := n.userClients[msg.User]
|
||||||
if !ok || len(clts) == 0{
|
if !ok || len(clts) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
newClts := []string{}
|
newClts := []string{}
|
||||||
for _, clt := range clts{
|
for _, clt := range clts {
|
||||||
client, ok := n.Consumers[clt]
|
client, ok := n.Consumers[clt]
|
||||||
if ok {
|
if ok {
|
||||||
err := client.Write(msg.Message)
|
err := client.Write(msg.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
delete(n.Consumers, clt)
|
delete(n.Consumers, clt)
|
||||||
}else{
|
} else {
|
||||||
newClts = append(newClts, clt)
|
newClts = append(newClts, clt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,36 +69,36 @@ func (n *Notifier)notify(msg Message){
|
||||||
n.userClients[msg.User] = newClts
|
n.userClients[msg.User] = newClts
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)recieveConsumer(ctx context.Context){
|
func (n *Notifier) recieveConsumer(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
select{
|
select {
|
||||||
case <- ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case c := <- n.consumerChan:
|
case c := <-n.consumerChan:
|
||||||
n.addConsumer(c)
|
n.addConsumer(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)addConsumer(c *Consumer){
|
func (n *Notifier) addConsumer(c *Consumer) {
|
||||||
n.lock.Lock()
|
n.lock.Lock()
|
||||||
defer n.lock.Unlock()
|
defer n.lock.Unlock()
|
||||||
n.Consumers[c.ClientID] = c
|
n.Consumers[c.ClientID] = c
|
||||||
us := []string{}
|
us := []string{}
|
||||||
if u, ok := n.userClients[c.UserID]; ok {
|
if u, ok := n.userClients[c.UserID]; ok {
|
||||||
us=append(us, u...)
|
us = append(us, u...)
|
||||||
}
|
}
|
||||||
us=append(us, c.ClientID)
|
us = append(us, c.ClientID)
|
||||||
n.userClients[c.UserID] = us
|
n.userClients[c.UserID] = us
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)Run(ctx context.Context){
|
func (n *Notifier) Run(ctx context.Context) {
|
||||||
go n.recieveConsumer(ctx)
|
go n.recieveConsumer(ctx)
|
||||||
n.recieveMessage(ctx)
|
n.recieveMessage(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier)SendMessage(user, msg string){
|
func (n *Notifier) SendMessage(user, msg string) {
|
||||||
go func () {
|
go func() {
|
||||||
n.messageChan <- Message{User: user, Message: msg}
|
n.messageChan <- Message{User: user, Message: msg}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ var (
|
||||||
clientSecret = "cbfd6e04-a51c-4982-a25b-7aaba4f30c81"
|
clientSecret = "cbfd6e04-a51c-4982-a25b-7aaba4f30c81"
|
||||||
|
|
||||||
redirectURL = "http://localhost:8181/demo/callback"
|
redirectURL = "http://localhost:8181/demo/callback"
|
||||||
state = "somestate"
|
state = "somestate"
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleRedirect(w http.ResponseWriter, r *http.Request) {
|
func handleRedirect(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
@ -217,119 +217,117 @@ func (a *AliOSS) CheckFileVersion(obj string, info os.FileInfo) (bool, error) {
|
||||||
return info.ModTime().Unix() >= modifiedAt, nil
|
return info.ModTime().Unix() >= modifiedAt, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// const host = "http://testspeed.xk.design"
|
// const host = "http://testspeed.xk.design"
|
||||||
|
|
||||||
const MAX = 300
|
const MAX = 300
|
||||||
|
|
||||||
type file struct{
|
type file struct {
|
||||||
Name string
|
Name string
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
Src string
|
Src string
|
||||||
}
|
}
|
||||||
|
|
||||||
var test1 = []file{
|
var test1 = []file{
|
||||||
{
|
{
|
||||||
Name: "test4k.jpg",
|
Name: "test4k.jpg",
|
||||||
Width: 0,
|
Width: 0,
|
||||||
Height: 0,
|
Height: 0,
|
||||||
Src: "test4k.jpg",
|
Src: "test4k.jpg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "test2k.jpg",
|
Name: "test2k.jpg",
|
||||||
Width: 2590,
|
Width: 2590,
|
||||||
Height: 1619,
|
Height: 1619,
|
||||||
Src: "test4k.jpg",
|
Src: "test4k.jpg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "test1k.jpg",
|
Name: "test1k.jpg",
|
||||||
Width: 1831,
|
Width: 1831,
|
||||||
Height: 1144,
|
Height: 1144,
|
||||||
Src: "test4k.jpg",
|
Src: "test4k.jpg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "test600.jpg",
|
Name: "test600.jpg",
|
||||||
Width: 647,
|
Width: 647,
|
||||||
Height: 404,
|
Height: 404,
|
||||||
Src: "test4k.jpg",
|
Src: "test4k.jpg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "test1of10.jpg",
|
Name: "test1of10.jpg",
|
||||||
Width: 384,
|
Width: 384,
|
||||||
Height: 240,
|
Height: 240,
|
||||||
Src: "test4k.jpg",
|
Src: "test4k.jpg",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var test2 = []file{
|
var test2 = []file{
|
||||||
{
|
{
|
||||||
Name: "8ktestsrc.jpeg",
|
Name: "8ktestsrc.jpeg",
|
||||||
Width: 7680,
|
Width: 7680,
|
||||||
Height: 4320,
|
Height: 4320,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "8ktest3k.jpeg",
|
Name: "8ktest3k.jpeg",
|
||||||
Width: 2730,
|
Width: 2730,
|
||||||
Height: 1536,
|
Height: 1536,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "8ktest1080.jpeg",
|
Name: "8ktest1080.jpeg",
|
||||||
Width: 1930,
|
Width: 1930,
|
||||||
Height: 1086,
|
Height: 1086,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "8ktest682.jpeg",
|
Name: "8ktest682.jpeg",
|
||||||
Width: 682,
|
Width: 682,
|
||||||
Height: 384,
|
Height: 384,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "8ktest400.jpeg",
|
Name: "8ktest400.jpeg",
|
||||||
Width: 400,
|
Width: 400,
|
||||||
Height: 225,
|
Height: 225,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "8ktest300.jpeg",
|
Name: "8ktest300.jpeg",
|
||||||
Width: 300,
|
Width: 300,
|
||||||
Height: 300,
|
Height: 300,
|
||||||
Src: "8ktestsrc.jpeg",
|
Src: "8ktestsrc.jpeg",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRequest(url string)(*http.Request, error){
|
func NewRequest(url string) (*http.Request, error) {
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Add("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9")
|
||||||
req.Header.Add("Accept-Encoding","gzip, deflate")
|
req.Header.Add("Accept-Encoding", "gzip, deflate")
|
||||||
req.Header.Add("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.56")
|
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.56")
|
||||||
req.Header.Add("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
|
req.Header.Add("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
|
||||||
req.Header.Add("Cache-Control","no-cache")
|
req.Header.Add("Cache-Control", "no-cache")
|
||||||
req.Header.Add("Connection"," keep-alive")
|
req.Header.Add("Connection", " keep-alive")
|
||||||
req.Header.Add("Cookie"," Hm_lvt_2e2c80c1bd8a51afc2d7de641330a397=1669089775,1669615598,1669704782,1669875251; Hm_lpvt_2e2c80c1bd8a51afc2d7de641330a397=1669964998")
|
req.Header.Add("Cookie", " Hm_lvt_2e2c80c1bd8a51afc2d7de641330a397=1669089775,1669615598,1669704782,1669875251; Hm_lpvt_2e2c80c1bd8a51afc2d7de641330a397=1669964998")
|
||||||
req.Header.Add("Host"," test-pic.xk.design")
|
req.Header.Add("Host", " test-pic.xk.design")
|
||||||
// req.Header.Add("If-Modified-Since"," Fri, 02 Dec 2022 06:31:28 GMT")
|
// req.Header.Add("If-Modified-Since"," Fri, 02 Dec 2022 06:31:28 GMT")
|
||||||
// req.Header.Add("If-None-Match","\"4B8579BA5E07DD57405973606E777476\"")
|
// req.Header.Add("If-None-Match","\"4B8579BA5E07DD57405973606E777476\"")
|
||||||
// req.Header.Add("Upgrade-Insecure-Requests","1")
|
// req.Header.Add("Upgrade-Insecure-Requests","1")
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func test(f file, count int, host string) {
|
||||||
func test(f file, count int, host string){
|
|
||||||
fmt.Printf("begin normal testing for %s\n", f.Name)
|
fmt.Printf("begin normal testing for %s\n", f.Name)
|
||||||
startedAt := time.Now().UnixMilli()
|
startedAt := time.Now().UnixMilli()
|
||||||
errCount := 0
|
errCount := 0
|
||||||
costMS := []int64{}
|
costMS := []int64{}
|
||||||
for i := 0; i < count; i ++ {
|
for i := 0; i < count; i++ {
|
||||||
req, err := NewRequest(host + "/" + f.Name)
|
req, err := NewRequest(host + "/" + f.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errCount ++
|
errCount++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
@ -355,13 +353,13 @@ func test(f file, count int, host string){
|
||||||
statistics(costMS)
|
statistics(costMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testResize(f file, count int, host string)(int64, int64, int64){
|
func testResize(f file, count int, host string) (int64, int64, int64) {
|
||||||
fmt.Printf("begin resize testing for %s\n", f.Name)
|
fmt.Printf("begin resize testing for %s\n", f.Name)
|
||||||
startedAt := time.Now().UnixMilli()
|
startedAt := time.Now().UnixMilli()
|
||||||
errCount := 0
|
errCount := 0
|
||||||
costMS := []int64{}
|
costMS := []int64{}
|
||||||
for i := 0; i < count; i ++ {
|
for i := 0; i < count; i++ {
|
||||||
query := "?x-oss-process=image/resize,m_lfit,w_"+strconv.Itoa(f.Width) + ",h_" + strconv.Itoa(f.Height)
|
query := "?x-oss-process=image/resize,m_lfit,w_" + strconv.Itoa(f.Width) + ",h_" + strconv.Itoa(f.Height)
|
||||||
if f.Height == 0 || f.Width == 0 {
|
if f.Height == 0 || f.Width == 0 {
|
||||||
query = ""
|
query = ""
|
||||||
}
|
}
|
||||||
|
@ -396,7 +394,7 @@ func testResize(f file, count int, host string)(int64, int64, int64){
|
||||||
return statistics(costMS)
|
return statistics(costMS)
|
||||||
}
|
}
|
||||||
|
|
||||||
func filelist(dir string)([]string, error){
|
func filelist(dir string) ([]string, error) {
|
||||||
fis, err := os.ReadDir(dir)
|
fis, err := os.ReadDir(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -410,20 +408,19 @@ func filelist(dir string)([]string, error){
|
||||||
return fs, nil
|
return fs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func case3(dir string, ak string, sk string, count int, host string) error {
|
||||||
func case3(dir string, ak string, sk string, count int, host string)error{
|
|
||||||
files, err := filelist(dir)
|
files, err := filelist(dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
alioss := NewAliOSS("oss-cn-hangzhou.aliyuncs.com", ak,sk, "oxslmimg")
|
alioss := NewAliOSS("oss-cn-hangzhou.aliyuncs.com", ak, sk, "oxslmimg")
|
||||||
alioss.Init()
|
alioss.Init()
|
||||||
avgmap := make(map[string][]string)
|
avgmap := make(map[string][]string)
|
||||||
p95map := make(map[string][]string)
|
p95map := make(map[string][]string)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
err = alioss.UploadFile(f, path.Join(dir,f))
|
err = alioss.UploadFile(f, path.Join(dir, f))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("upload failed:", err, f, path.Join(dir,f))
|
fmt.Println("upload failed:", err, f, path.Join(dir, f))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
avgmap[f] = []string{}
|
avgmap[f] = []string{}
|
||||||
|
@ -446,7 +443,7 @@ func case3(dir string, ak string, sk string, count int, host string)error{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func avg(data []int64)int64{
|
func avg(data []int64) int64 {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -454,7 +451,7 @@ func avg(data []int64)int64{
|
||||||
for _, i := range data {
|
for _, i := range data {
|
||||||
total = total + i
|
total = total + i
|
||||||
}
|
}
|
||||||
return total/int64(len(data))
|
return total / int64(len(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
type SortInt64 []int64
|
type SortInt64 []int64
|
||||||
|
@ -463,44 +460,44 @@ func (a SortInt64) Len() int { return len(a) }
|
||||||
func (a SortInt64) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a SortInt64) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
func (a SortInt64) Less(i, j int) bool { return a[i] < a[j] }
|
func (a SortInt64) Less(i, j int) bool { return a[i] < a[j] }
|
||||||
|
|
||||||
func percent50(data []int64)int64{
|
func percent50(data []int64) int64 {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
i := int(float64(len(data)) * 0.5 )
|
i := int(float64(len(data)) * 0.5)
|
||||||
if i == len(data) {
|
if i == len(data) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return data[i]
|
return data[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func percent90(data []int64)int64{
|
func percent90(data []int64) int64 {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
i := int(float64(len(data)) * 0.9 )
|
i := int(float64(len(data)) * 0.9)
|
||||||
if i == len(data) {
|
if i == len(data) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return data[i]
|
return data[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func percent95(data []int64)int64{
|
func percent95(data []int64) int64 {
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
i := int(float64(len(data)) * 0.95 )
|
i := int(float64(len(data)) * 0.95)
|
||||||
if i == len(data) {
|
if i == len(data) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return data[i]
|
return data[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func max(data []int64)int64{
|
func max(data []int64) int64 {
|
||||||
return data[len(data)-1]
|
return data[len(data)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func statistics(data []int64)(int64, int64, int64){
|
func statistics(data []int64) (int64, int64, int64) {
|
||||||
a := avg(data)
|
a := avg(data)
|
||||||
sort.Sort(SortInt64(data))
|
sort.Sort(SortInt64(data))
|
||||||
m := percent50(data)
|
m := percent50(data)
|
||||||
|
@ -511,7 +508,7 @@ func statistics(data []int64)(int64, int64, int64){
|
||||||
return a, p95, ma
|
return a, p95, ma
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
var tcase, count int
|
var tcase, count int
|
||||||
var host, ak, sk, dir string
|
var host, ak, sk, dir string
|
||||||
flag.IntVar(&tcase, "case", 1, "which test case to use")
|
flag.IntVar(&tcase, "case", 1, "which test case to use")
|
||||||
|
@ -519,20 +516,20 @@ func main(){
|
||||||
flag.StringVar(&host, "host", "http://testspeed.xk.design", "access host")
|
flag.StringVar(&host, "host", "http://testspeed.xk.design", "access host")
|
||||||
flag.StringVar(&ak, "ak", "", "access key")
|
flag.StringVar(&ak, "ak", "", "access key")
|
||||||
flag.StringVar(&sk, "sk", "", "access secret")
|
flag.StringVar(&sk, "sk", "", "access secret")
|
||||||
flag.StringVar(&dir , "dir", "", "img path")
|
flag.StringVar(&dir, "dir", "", "img path")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
switch tcase {
|
switch tcase {
|
||||||
case 1:
|
case 1:
|
||||||
for _, f := range test1 {
|
for _, f := range test1 {
|
||||||
test(f, count, host)
|
test(f, count, host)
|
||||||
testResize(f, count, host)
|
testResize(f, count, host)
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
for _, f := range test2 {
|
for _, f := range test2 {
|
||||||
test(f, count, host)
|
test(f, count, host)
|
||||||
testResize(f, count, host)
|
testResize(f, count, host)
|
||||||
}
|
}
|
||||||
case 3:
|
case 3:
|
||||||
case3(dir, ak, sk, count, host)
|
case3(dir, ak, sk, count, host)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/skip2/go-qrcode"
|
"github.com/skip2/go-qrcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
code, err := qrcode.New("http://weixin.qq.com/q/02vEhthpJ1fqD1mfbvxzcy", qrcode.High)
|
code, err := qrcode.New("http://weixin.qq.com/q/02vEhthpJ1fqD1mfbvxzcy", qrcode.High)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -22,4 +22,4 @@ func main(){
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Send = "二进制消息 2.6 kB"
|
Send = "二进制消息 2.6 kB"
|
||||||
Recieve = "二进制消息 3.9 kB"
|
Recieve = "二进制消息 3.9 kB"
|
||||||
Broadcast = "二进制消息 16 B"
|
Broadcast = "二进制消息 16 B"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ type message struct {
|
||||||
Time int64
|
Time int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func time2int64(t string)int64{
|
func time2int64(t string) int64 {
|
||||||
strs := strings.Split(t, ":")
|
strs := strings.Split(t, ":")
|
||||||
if len(strs) != 3 {
|
if len(strs) != 3 {
|
||||||
return 0
|
return 0
|
||||||
|
@ -36,7 +36,7 @@ func time2int64(t string)int64{
|
||||||
}
|
}
|
||||||
second := seconds[0]
|
second := seconds[0]
|
||||||
mill := seconds[1]
|
mill := seconds[1]
|
||||||
|
|
||||||
ms, err := strconv.ParseInt(mill, 10, 64)
|
ms, err := strconv.ParseInt(mill, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -47,23 +47,23 @@ func time2int64(t string)int64{
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
ms = ms + h *3600*1000
|
ms = ms + h*3600*1000
|
||||||
m, err := strconv.ParseInt(minute, 10, 64)
|
m, err := strconv.ParseInt(minute, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
ms = ms + m * 60 *1000
|
ms = ms + m*60*1000
|
||||||
s, err := strconv.ParseInt(second, 10, 64)
|
s, err := strconv.ParseInt(second, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
ms = ms + s *1000
|
ms = ms + s*1000
|
||||||
return ms
|
return ms
|
||||||
}
|
}
|
||||||
|
|
||||||
func readdelay(file string)([]message, error){
|
func readdelay(file string) ([]message, error) {
|
||||||
f, err := os.Open(file)
|
f, err := os.Open(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -84,14 +84,14 @@ func readdelay(file string)([]message, error){
|
||||||
switch {
|
switch {
|
||||||
case strings.Contains(line, Send):
|
case strings.Contains(line, Send):
|
||||||
t = 1
|
t = 1
|
||||||
case strings.Contains(line, Recieve):
|
case strings.Contains(line, Recieve):
|
||||||
t = 2
|
t = 2
|
||||||
case strings.Contains(line, Broadcast):
|
case strings.Contains(line, Broadcast):
|
||||||
t = 3
|
t = 3
|
||||||
default:
|
default:
|
||||||
msg := message{Type: t, Time: time2int64(line)}
|
msg := message{Type: t, Time: time2int64(line)}
|
||||||
switch t {
|
switch t {
|
||||||
case 1 :
|
case 1:
|
||||||
res = append(res, msg)
|
res = append(res, msg)
|
||||||
case 2:
|
case 2:
|
||||||
res = append(res, msg)
|
res = append(res, msg)
|
||||||
|
@ -101,7 +101,7 @@ func readdelay(file string)([]message, error){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func avg(delays ...int64)int64{
|
func avg(delays ...int64) int64 {
|
||||||
if len(delays) == 0 {
|
if len(delays) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,10 @@ func avg(delays ...int64)int64{
|
||||||
for _, d := range delays {
|
for _, d := range delays {
|
||||||
total = total + d
|
total = total + d
|
||||||
}
|
}
|
||||||
return total/int64(len(delays))
|
return total / int64(len(delays))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
var file string
|
var file string
|
||||||
flag.StringVar(&file, "f", "delay.log", "ssss")
|
flag.StringVar(&file, "f", "delay.log", "ssss")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
@ -134,4 +134,4 @@ func main(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Println(avg(delays...))
|
fmt.Println(avg(delays...))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
package main
|
package main
|
||||||
|
|
16
go/test.go
16
go/test.go
|
@ -1,30 +1,30 @@
|
||||||
package test
|
package test
|
||||||
|
|
||||||
type Cmd interface{
|
type Cmd interface {
|
||||||
Result()bool
|
Result() bool
|
||||||
Output()string
|
Output() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type cmd struct{
|
type cmd struct {
|
||||||
r bool
|
r bool
|
||||||
o string
|
o string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmd)exec(s string, args ...string){
|
func (c *cmd) exec(s string, args ...string) {
|
||||||
//....
|
//....
|
||||||
// c.r = ...
|
// c.r = ...
|
||||||
//c.o = ...
|
//c.o = ...
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmd)Result()bool{
|
func (c *cmd) Result() bool {
|
||||||
return c.r
|
return c.r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *cmd)Output()string{
|
func (c *cmd) Output() string {
|
||||||
return c.o
|
return c.o
|
||||||
}
|
}
|
||||||
|
|
||||||
func Exec(s string, args ...string)Cmd{
|
func Exec(s string, args ...string) Cmd {
|
||||||
c := &cmd{}
|
c := &cmd{}
|
||||||
c.exec(s, args...)
|
c.exec(s, args...)
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,16 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(dir, title, addr string)error{
|
func run(dir, title, addr string) error {
|
||||||
engine := gin.Default()
|
engine := gin.Default()
|
||||||
engine.LoadHTMLGlob(dir + "/*.tmpl")
|
engine.LoadHTMLGlob(dir + "/*.tmpl")
|
||||||
engine.Static("/ui", dir)
|
engine.Static("/ui", dir)
|
||||||
engine.StaticFS("/SC", http.Dir(dir + "/SC"))
|
engine.StaticFS("/SC", http.Dir(dir+"/SC"))
|
||||||
engine.GET("/", func(ctx *gin.Context) {
|
engine.GET("/", func(ctx *gin.Context) {
|
||||||
dirs, _ := os.ReadDir(dir)
|
dirs, _ := os.ReadDir(dir)
|
||||||
files := []string{}
|
files := []string{}
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
if !d.IsDir() {
|
if !d.IsDir() {
|
||||||
|
@ -36,14 +35,14 @@ func run(dir, title, addr string)error{
|
||||||
return engine.Run(addr)
|
return engine.Run(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
var dir, title, addr string
|
var dir, title, addr string
|
||||||
flag.StringVar(&dir, "dir", "./", "service dir")
|
flag.StringVar(&dir, "dir", "./", "service dir")
|
||||||
flag.StringVar(&title, "title", "无标题", "website title")
|
flag.StringVar(&title, "title", "无标题", "website title")
|
||||||
flag.StringVar(&addr,"addr", ":3000", "listen port")
|
flag.StringVar(&addr, "addr", ":3000", "listen port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
err := run(dir, title, addr)
|
err := run(dir, title, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func (s *Server) handleGet(c *gin.Context) {
|
||||||
c.String(http.StatusOK, echoStr)
|
c.String(http.StatusOK, echoStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//关注
|
// 关注
|
||||||
func (s *Server) handlePost(c *gin.Context) {
|
func (s *Server) handlePost(c *gin.Context) {
|
||||||
data := wechat.FoucsRequest{}
|
data := wechat.FoucsRequest{}
|
||||||
err := c.BindXML(&data)
|
err := c.BindXML(&data)
|
||||||
|
@ -107,7 +107,7 @@ func (s *Server) handleDelete(c *gin.Context) {
|
||||||
c.String(http.StatusOK, "success")
|
c.String(http.StatusOK, "success")
|
||||||
}
|
}
|
||||||
|
|
||||||
//@router /auth/login
|
// @router /auth/login
|
||||||
func (s *Server) login(c *gin.Context) {
|
func (s *Server) login(c *gin.Context) {
|
||||||
code := c.Query("code")
|
code := c.Query("code")
|
||||||
if code == "" {
|
if code == "" {
|
||||||
|
@ -153,7 +153,7 @@ func (s *Server) Run(addr string) error {
|
||||||
return engine.Run(addr)
|
return engine.Run(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc39301065b66300c&redirect_uri=http://106.55.59.210:15043/auth/login&response_type=code&scope=snsapi_userinfo#wechat_redirect
|
// https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc39301065b66300c&redirect_uri=http://106.55.59.210:15043/auth/login&response_type=code&scope=snsapi_userinfo#wechat_redirect
|
||||||
// https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc39301065b66300c&redirect_uri=http%3A%2F%2F106.55.59.210%3A15043%2Fauth%2Flogin&response_type=code&scope=snsapi_userinfo&connect_redirect=1#wechat_redirect
|
// https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc39301065b66300c&redirect_uri=http%3A%2F%2F106.55.59.210%3A15043%2Fauth%2Flogin&response_type=code&scope=snsapi_userinfo&connect_redirect=1#wechat_redirect
|
||||||
func main() {
|
func main() {
|
||||||
s, err := NewServer()
|
s, err := NewServer()
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (m *Message) Show() {
|
||||||
fmt.Println(string(data))
|
fmt.Println(string(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
//////
|
// ////
|
||||||
type MessageEntity struct {
|
type MessageEntity struct {
|
||||||
Signature string `form:"signature"`
|
Signature string `form:"signature"`
|
||||||
Timestamp string `form:"timestamp"`
|
Timestamp string `form:"timestamp"`
|
||||||
|
@ -66,19 +66,19 @@ type FoucsRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
"subscribe": 1,
|
"subscribe": 1,
|
||||||
"openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
|
"openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
|
||||||
"language": "zh_CN",
|
"language": "zh_CN",
|
||||||
"subscribe_time": 1382694957,
|
"subscribe_time": 1382694957,
|
||||||
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL",
|
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL",
|
||||||
"remark": "",
|
"remark": "",
|
||||||
"groupid": 0,
|
"groupid": 0,
|
||||||
"tagid_list":[128,2],
|
"tagid_list":[128,2],
|
||||||
"subscribe_scene": "ADD_SCENE_QR_CODE",
|
"subscribe_scene": "ADD_SCENE_QR_CODE",
|
||||||
"qr_scene": 98765,
|
"qr_scene": 98765,
|
||||||
"qr_scene_str": ""
|
"qr_scene_str": ""
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
type UserInfo struct {
|
type UserInfo struct {
|
||||||
Subscribe int `json:"subscribe"`
|
Subscribe int `json:"subscribe"`
|
||||||
|
|
|
@ -14,7 +14,7 @@ type Token struct {
|
||||||
ExpiresIn int64 `json:"expires_in"`
|
ExpiresIn int64 `json:"expires_in"`
|
||||||
ExpiredAt int64 `json:"expiredAt"`
|
ExpiredAt int64 `json:"expiredAt"`
|
||||||
ErrCode int `json:"errcode"`
|
ErrCode int `json:"errcode"`
|
||||||
ErrMsg string `json:"errmsg"`
|
ErrMsg string `json:"errmsg"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Wechat struct {
|
type Wechat struct {
|
||||||
|
@ -83,7 +83,7 @@ func (w *Wechat) SendText(to, text string) ([]byte, error) {
|
||||||
return data, err
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wechat)GetUserInfo(openID string)(*UserInfo, error){
|
func (w *Wechat) GetUserInfo(openID string) (*UserInfo, error) {
|
||||||
token, err := w.queryToken()
|
token, err := w.queryToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -98,7 +98,7 @@ func (w *Wechat)GetUserInfo(openID string)(*UserInfo, error){
|
||||||
return &ui, err
|
return &ui, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wechat)GetGrantToken(code string)(*GrantToken, error){
|
func (w *Wechat) GetGrantToken(code string) (*GrantToken, error) {
|
||||||
url := fmt.Sprintf("%s?%s&code=%s&grant_type=authorization_code", APIGetGrantToken, w.queryStr(), code)
|
url := fmt.Sprintf("%s?%s&code=%s&grant_type=authorization_code", APIGetGrantToken, w.queryStr(), code)
|
||||||
|
|
||||||
data, err := curl.SimpleGet(url)
|
data, err := curl.SimpleGet(url)
|
||||||
|
@ -109,24 +109,25 @@ func (w *Wechat)GetGrantToken(code string)(*GrantToken, error){
|
||||||
err = json.Unmarshal(data, &token)
|
err = json.Unmarshal(data, &token)
|
||||||
return &token, err
|
return &token, err
|
||||||
}
|
}
|
||||||
//{"expire_seconds":"60","action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": '.$id.'}}}
|
|
||||||
type Scene struct{
|
// {"expire_seconds":"60","action_name": "QR_STR_SCENE", "action_info": {"scene": {"scene_str": '.$id.'}}}
|
||||||
|
type Scene struct {
|
||||||
Str string `json:"scene_str"`
|
Str string `json:"scene_str"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionInfo struct {
|
type ActionInfo struct {
|
||||||
ActionInfo Scene `json:"scene"`
|
ActionInfo Scene `json:"scene"`
|
||||||
}
|
}
|
||||||
type qrCodeRequest struct{
|
type qrCodeRequest struct {
|
||||||
ExpireSeconds int `json:"expire_seconds"`
|
ExpireSeconds int `json:"expire_seconds"`
|
||||||
Action string `json:"action_name"`
|
Action string `json:"action_name"`
|
||||||
ActionInfo ActionInfo `json:"action_info"`
|
ActionInfo ActionInfo `json:"action_info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Wechat)CreateQRCode()(*Ticket, error){
|
func (w *Wechat) CreateQRCode() (*Ticket, error) {
|
||||||
req := qrCodeRequest{
|
req := qrCodeRequest{
|
||||||
ExpireSeconds: 3600,
|
ExpireSeconds: 3600,
|
||||||
Action: "QR_STR_SCENE",
|
Action: "QR_STR_SCENE",
|
||||||
ActionInfo: ActionInfo{
|
ActionInfo: ActionInfo{
|
||||||
Scene{
|
Scene{
|
||||||
Str: fmt.Sprintf("aaa%d", time.Now().UnixNano()),
|
Str: fmt.Sprintf("aaa%d", time.Now().UnixNano()),
|
||||||
|
@ -145,4 +146,4 @@ func (w *Wechat)CreateQRCode()(*Ticket, error){
|
||||||
ticket := Ticket{}
|
ticket := Ticket{}
|
||||||
err = json.Unmarshal(data, &ticket)
|
err = json.Unmarshal(data, &ticket)
|
||||||
return &ticket, err
|
return &ticket, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ func connectCluster() (*kubernetes.Clientset, error) {
|
||||||
config, err := clientcmd.BuildConfigFromFlags("", conf)
|
config, err := clientcmd.BuildConfigFromFlags("", conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
clientset, err := kubernetes.NewForConfig(config)
|
clientset, err := kubernetes.NewForConfig(config)
|
||||||
return clientset, err
|
return clientset, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/gomarkdown/markdown/parser"
|
"github.com/gomarkdown/markdown/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main(){
|
func main() {
|
||||||
file, err := os.Open("test.md")
|
file, err := os.Open("test.md")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -28,11 +28,11 @@ func main(){
|
||||||
parser.Strikethrough |
|
parser.Strikethrough |
|
||||||
parser.SpaceHeadings
|
parser.SpaceHeadings
|
||||||
opts := html.RendererOptions{
|
opts := html.RendererOptions{
|
||||||
Flags: htmlFlags,
|
Flags: htmlFlags,
|
||||||
CSS: "http://www.bing89.com/css/markdown/fluent.css",
|
CSS: "http://www.bing89.com/css/markdown/fluent.css",
|
||||||
}
|
}
|
||||||
renderer := html.NewRenderer(opts)
|
renderer := html.NewRenderer(opts)
|
||||||
parser := parser.NewWithExtensions(extensions)
|
parser := parser.NewWithExtensions(extensions)
|
||||||
html := markdown.ToHTML(data, parser, renderer)
|
html := markdown.ToHTML(data, parser, renderer)
|
||||||
fmt.Println(string(html))
|
fmt.Println(string(html))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue