update main add inputs and outputs
This commit is contained in:
37
main.go
37
main.go
@@ -1,7 +1,40 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, World!")
|
||||
username := readInputs()
|
||||
fmt.Printf("username is %s\n", username)
|
||||
|
||||
err := writeOutputs("time", time.Now().Format("2006-01-02 15:04:05"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user