From 72bc792ed8479879ade6a79875659ad5aecb3907 Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Sat, 20 Jul 2024 11:26:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=95=9C=E5=83=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=9C=BA=E5=99=A8=E4=BA=BA=E7=9A=84=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E7=94=A8=E6=88=B7=E5=92=8C=E5=AF=86=E7=A0=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- practise/http-practise/sse.go | 35 +++++++++++++++++++++++++++++++++ practise/image-practise/main.go | 18 +++++++++++++++-- practise/sftp-practise.go | 6 ++++++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 practise/http-practise/sse.go diff --git a/practise/http-practise/sse.go b/practise/http-practise/sse.go new file mode 100644 index 00000000..850bbbcb --- /dev/null +++ b/practise/http-practise/sse.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "net/http" + "time" +) + +func sseHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/event-stream") + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Connection", "keep-alive") + + for { + + fmt.Println("start time", time.Now()) + _, err := fmt.Fprintf(w, "data: %s", "hello world") + if err != nil { + fmt.Println("err", err) + } + + flusher, _ := w.(http.Flusher) + flusher.Flush() + + fmt.Println("end time", time.Now()) + fmt.Println("==========") + + <-time.After(5 * time.Second) + } +} + +func main() { + http.HandleFunc("/sse", sseHandler) + http.ListenAndServe(":8081", nil) +} diff --git a/practise/image-practise/main.go b/practise/image-practise/main.go index 5ca82127..67fb7398 100644 --- a/practise/image-practise/main.go +++ b/practise/image-practise/main.go @@ -9,6 +9,11 @@ import ( "go-learning/practise/image-practise/image" ) +const ( + defaultUser = "pixiu" + defaultPassword = "123456" +) + var ( harbor = flag.String("harbor", "harbor.cloud.pixiuio.com", "Choose a harbor to push (default harbor.cloud.pixiuio.com") imageRepository = flag.String("image-repository", "pixiuio", "Choose a container registry to push (default pixiuio") @@ -32,11 +37,20 @@ func main() { klog.Fatal(err) } + loginUser := *user + if len(loginUser) == 0 { + loginUser = defaultUser + } + loginPassword := *password + if len(loginPassword) == 0 { + loginPassword = defaultPassword + } + img := image.Image{ Harbor: *harbor, ImageRepository: *imageRepository, - User: *user, - Password: *password, + User: loginUser, + Password: loginPassword, Cfg: cfg, } diff --git a/practise/sftp-practise.go b/practise/sftp-practise.go index e7deadf9..3dde7cab 100644 --- a/practise/sftp-practise.go +++ b/practise/sftp-practise.go @@ -70,6 +70,12 @@ func CopyFromRemote(remoteFile, localFile, user, passwd, host string, port int) } defer srcFile.Close() + // 直接读到内存 + //buf, err := io.ReadAll(srcFile) + //if err != nil { + // return nil, err + //} + f, err := os.Create(localFile) if err != nil { return fmt.Errorf("create file %s failed %v", localFile, err) From fe718bd311f85833af222fb86545b50538e37109 Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Sat, 20 Jul 2024 11:27:42 +0800 Subject: [PATCH 2/4] add --- practise/http-practise/sse.go | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 practise/http-practise/sse.go diff --git a/practise/http-practise/sse.go b/practise/http-practise/sse.go deleted file mode 100644 index 850bbbcb..00000000 --- a/practise/http-practise/sse.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "fmt" - "net/http" - "time" -) - -func sseHandler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/event-stream") - w.Header().Set("Cache-Control", "no-cache") - w.Header().Set("Connection", "keep-alive") - - for { - - fmt.Println("start time", time.Now()) - _, err := fmt.Fprintf(w, "data: %s", "hello world") - if err != nil { - fmt.Println("err", err) - } - - flusher, _ := w.(http.Flusher) - flusher.Flush() - - fmt.Println("end time", time.Now()) - fmt.Println("==========") - - <-time.After(5 * time.Second) - } -} - -func main() { - http.HandleFunc("/sse", sseHandler) - http.ListenAndServe(":8081", nil) -} From c82b7266768e0411c30689e9a573a953d931ac8a Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Sat, 20 Jul 2024 12:54:39 +0800 Subject: [PATCH 3/4] add --- practise/image-practise/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/practise/image-practise/main.go b/practise/image-practise/main.go index 67fb7398..27e7111a 100644 --- a/practise/image-practise/main.go +++ b/practise/image-practise/main.go @@ -38,7 +38,7 @@ func main() { } loginUser := *user - if len(loginUser) == 0 { + if len(loginUser) == 0 || loginUser == "--password" { loginUser = defaultUser } loginPassword := *password From a40eddb69bfb376bf7d7ba330da1d375675db54e Mon Sep 17 00:00:00 2001 From: caoyingjunz Date: Sat, 20 Jul 2024 13:02:57 +0800 Subject: [PATCH 4/4] add --- .github/workflows/main.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fa778cb4..dce97f56 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,12 +17,12 @@ env: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - misspell-check: - runs-on: ubuntu-latest - container: pouchcontainer/pouchlinter:v0.1.2 - steps: - - name: Checkout - uses: actions/checkout@v2 +# misspell-check: +# runs-on: ubuntu-latest +# container: pouchcontainer/pouchlinter:v0.1.2 +# steps: +# - name: Checkout +# uses: actions/checkout@v2 # - name: Lint markdown files # run: find ./ -name "*.md" | xargs mdl -r ~MD010,~MD013,~MD022,~MD024,~MD029,~MD031,~MD032,~MD033,~MD034,~MD036