Skip to content

Commit

Permalink
go
Browse files Browse the repository at this point in the history
  • Loading branch information
SunEve committed May 6, 2024
1 parent 8da6797 commit 4282548
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/autotv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ on:
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Run script
run: sh autotv.sh
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18

- name: 'Gen New Year Calendar'
run: go run autotv.go

- name: 'Show Diff'
run: git add .

- name: 'Push file'
uses: actions-go/push@7ad7ce209f2a038e7bca929b7a4c92026363f856
with:
commit-message: "new file"
remote: origin
43 changes: 43 additions & 0 deletions autotv.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"io"
"net/http"
"os"
)

func downloadFile(url, filepath string) error {
// 发起 HTTP GET 请求
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// 创建文件来保存下载的内容
out, err := os.Create(filepath)
if err != nil {
return err
}
defer out.Close()

// 将下载的内容保存到文件
_, err = io.Copy(out, resp.Body)
if err != nil {
return err
}

fmt.Printf("文件 %s 下载完成\n", filepath)
return nil
}

func main() {
fileURL := "https://iitzh.com/cn.m3u"
filePath := "cn.m3u"

err := downloadFile(fileURL, filePath)
if err != nil {
fmt.Println("下载文件时出错:", err)
}
}

0 comments on commit 4282548

Please sign in to comment.