up
This commit is contained in:
24
tests/dl.go
Normal file
24
tests/dl.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func main() {
|
||||
dlpath := "http://pan.oneisall.xyz/Outline.apk"
|
||||
req, _ := http.NewRequest(http.MethodHead, dlpath, nil)
|
||||
rsp, _ := http.DefaultClient.Do(req)
|
||||
defer rsp.Body.Close()
|
||||
fmt.Println(rsp.Status)
|
||||
// dump, _ := httputil.DumpResponse(rsp, false)
|
||||
// fmt.Println(string(dump))
|
||||
// if rsp.Header != nil {
|
||||
// fmt.Printf("%v", rsp.Header)
|
||||
for k, v := range rsp.Header {
|
||||
fmt.Println(k, v)
|
||||
}
|
||||
fmt.Println(rsp.Header.Get("Content-Length"))
|
||||
fmt.Println(rsp.Header.Get("Accept-Ranges"))
|
||||
|
||||
}
|
||||
54
tests/dump.go
Normal file
54
tests/dump.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
bytereq, _ := httputil.DumpRequest(r, true)
|
||||
bytebody, _ := io.ReadAll(r.Body)
|
||||
log.Println(string(bytereq))
|
||||
m := map[string]interface{}{
|
||||
"host": r.Host,
|
||||
"requestUrl": r.RequestURI,
|
||||
"proto": r.Proto,
|
||||
"path": r.URL.String(),
|
||||
"method": r.Method,
|
||||
"body": string(bytebody),
|
||||
"header": r.Header,
|
||||
"form": r.Form,
|
||||
"postform": r.PostForm,
|
||||
"dumpreq": string(bytereq),
|
||||
}
|
||||
bj, _ := json.Marshal(m)
|
||||
fmt.Println(string(bj))
|
||||
// json.NewEncoder(w).Encode(m)
|
||||
|
||||
for k, v := range cors {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
io.WriteString(w, string(bj))
|
||||
return
|
||||
})
|
||||
server := http.Server{
|
||||
Addr: ":890",
|
||||
Handler: mux,
|
||||
}
|
||||
server.ListenAndServe()
|
||||
}
|
||||
|
||||
var cors = map[string]string{
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "POST,OPTIONS,GET",
|
||||
"Access-Control-Max-Age": "3600",
|
||||
"Access-Control-Allow-Headers": "accept,x-requested-with,Content-Type",
|
||||
"Access-Control-Allow-Credentials": "true",
|
||||
}
|
||||
18
tests/lru.go
Normal file
18
tests/lru.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
func main() {
|
||||
l, _ := lru.New(10)
|
||||
for i := 0; i < 100; i++ {
|
||||
l.Add(i, i)
|
||||
}
|
||||
for l.Len() > 0 {
|
||||
fmt.Println(l.RemoveOldest())
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user