9
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 17s
Details
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 17s
Details
This commit is contained in:
parent
7af945e3f9
commit
f4f8c0ef01
43
main.go
43
main.go
|
@ -1,50 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
username := readInputs()
|
||||
c.String(http.StatusOK, fmt.Sprintf("username is %s\n", username))
|
||||
|
||||
err := writeOutputs("time", time.Now().Format("2006-01-02 15:04:05"))
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, fmt.Sprintf("Error: %v\n", err))
|
||||
return
|
||||
}
|
||||
r.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
|
||||
r.Run() // 默认在 0.0.0.0:8080 启动服务
|
||||
}
|
||||
|
||||
func readInputs() string {
|
||||
username := os.Getenv("INPUT_USERNAME")
|
||||
return username
|
||||
}
|
||||
|
||||
func writeOutputs(k, v string) (err error) {
|
||||
msg := fmt.Sprintf("%s=%s", k, v)
|
||||
outputFilepath := os.Getenv("GITHUB_OUTPUT")
|
||||
f, err := os.OpenFile(outputFilepath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if cErr := f.Close(); cErr != nil && err == nil {
|
||||
err = cErr
|
||||
}
|
||||
}()
|
||||
if _, err = f.Write([]byte(msg)); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
})
|
||||
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue