diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..2dad00d --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,32 @@ +name: gofmt + zls + +on: + push: + branches: ["main"] + tags: ["v*.*.*"] + pull_request: + types: [opened, reopened, synchronize] + branches: ["*"] + workflow_dispatch: + +jobs: + format: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - name: Setup go + uses: actions/setup-go@v5 + - name: Format all go files + run: (cd ./2024/go/ && go fmt ./...) + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5.0.1 + with: + commit_message: | + Autoformatting with gofmt + zls + + [skip ci] diff --git a/2024/go/day2/main.go b/2024/go/day2/main.go new file mode 100644 index 0000000..7ee82ce --- /dev/null +++ b/2024/go/day2/main.go @@ -0,0 +1,22 @@ +package main; + +import ( + "os" + "flag" +) + +func main() { + flag.Parse() + + if len(flag.Args()) == 0 { + panic("Please provide a filename") + } + + filename := flag.Args()[0] + + file, err := os.Open(filename) + if err != nil { + panic(err) + } + defer file.Close() +}