Skip to content

Commit 46a45e1

Browse files
feat: added new features
1 parent 756aa21 commit 46a45e1

File tree

12 files changed

+259
-20
lines changed

12 files changed

+259
-20
lines changed
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{{ range .Versions }}
2+
<a name="{{ .Tag.Name }}"></a>
3+
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})
4+
5+
{{ range .CommitGroups -}}
6+
### {{ .Title }}
7+
8+
{{ range .Commits -}}
9+
* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
10+
{{ end }}
11+
{{ end -}}
12+
13+
{{- if .RevertCommits -}}
14+
### Reverts
15+
16+
{{ range .RevertCommits -}}
17+
* {{ .Revert.Header }}
18+
{{ end }}
19+
{{ end -}}
20+
21+
{{- if .MergeCommits -}}
22+
### Pull Requests
23+
24+
{{ range .MergeCommits -}}
25+
* {{ .Header }}
26+
{{ end }}
27+
{{ end -}}
28+
29+
{{- if .NoteGroups -}}
30+
{{ range .NoteGroups -}}
31+
### {{ .Title }}
32+
33+
{{ range .Notes }}
34+
{{ .Body }}
35+
{{ end }}
36+
{{ end -}}
37+
{{ end -}}
38+
{{ end -}}

.github/workflows/.chglog/config.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
style: github
2+
template: CHANGELOG.tpl.md
3+
info:
4+
title: CHANGELOG
5+
repository_url: https://github.com/deweysasser/golang-program
6+
options:
7+
commits:
8+
# filters:
9+
# Type:
10+
# - feat
11+
# - fix
12+
# - perf
13+
# - refactor
14+
commit_groups:
15+
# title_maps:
16+
# feat: Features
17+
# fix: Bug Fixes
18+
# perf: Performance Improvements
19+
# refactor: Code Refactoring
20+
header:
21+
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
22+
pattern_maps:
23+
- Type
24+
- Scope
25+
- Subject
26+
notes:
27+
keywords:
28+
- BREAKING CHANGE

.github/workflows/build.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
on:
2+
push:
3+
branches:
4+
- "**"
5+
6+
name: Build
7+
env:
8+
GO_VERSION: 1.23
9+
10+
jobs:
11+
build:
12+
name: Run checks and build
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: ${{env.GO_VERSION}}
21+
22+
- name: Vet
23+
run: make vet
24+
25+
- name: Test
26+
run: make test
27+
28+
- name: Build
29+
run: make
30+
31+
format:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Set up Go
37+
uses: actions/setup-go@v5
38+
with:
39+
go-version: ${{env.GO_VERSION}}
40+
41+
- run: go fmt ./...

.github/workflows/release.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Release
2+
# on:
3+
# push:
4+
# tags: [ v* ]
5+
on:
6+
push:
7+
branches:
8+
- "**"
9+
10+
env:
11+
GO_VERSION: 1.23
12+
REPO: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
GOOS: [linux, darwin, windows]
20+
GOARCH: [amd64, arm64]
21+
include:
22+
- GOOS: windows
23+
ext: .exe
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
29+
with:
30+
go-version: ${{ env.GO_VERSION }}
31+
32+
- name: Repo Name
33+
id: repo-name
34+
run: echo name=$(basename ${{ github.repository }}) >> $GITHUB_OUTPUT
35+
36+
- name: Test
37+
run: go test -v ./...
38+
39+
- name: Build
40+
run: make package PROGRAM=${{ env.GOOS }}-${{ env.GOARCH }}/${{ steps.repo-name.outputs.name }}${{ matrix.ext }} PACKAGE=dist/${{ steps.repo-name.outputs.name }}-${{ matrix.GOOS }}-${{ matrix.GOARCH }}.zip
41+
env:
42+
GOOS: ${{ matrix.GOOS }}
43+
GOARCH: ${{ matrix.GOARCH }}
44+
45+
- name: 'Upload Artifact'
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: artifacts-${{ matrix.GOOS }}-${{ matrix.GOARCH }}
49+
path: dist
50+
retention-days: 1
51+
if-no-files-found: error
52+
53+
release:
54+
runs-on: ubuntu-latest
55+
needs:
56+
- build
57+
steps:
58+
- uses: actions/checkout@v4
59+
with:
60+
fetch-depth: 0
61+
62+
- name: Download Artifacts
63+
uses: actions/download-artifact@v4
64+
with:
65+
path: artifacts
66+
pattern: artifacts-*
67+
merge-multiple: true
68+
69+
- name: Install ChangeLog generator
70+
run: |
71+
wget https://github.com/git-chglog/git-chglog/releases/download/v0.15.1/git-chglog_0.15.1_linux_amd64.tar.gz
72+
tar xzf git-chglog*.tar.gz git-chglog
73+
- name: "Get Last Release"
74+
id: last_release
75+
uses: InsonusK/[email protected]
76+
with:
77+
myToken: ${{ github.token }}
78+
exclude_types: "draft|prerelease"
79+
80+
- name: Generate Changelog for ${{ github.ref_name }}
81+
id: generate-changelog
82+
run: PATH="${PATH}:." make CHANGELOG.md
83+
84+
- name: Generate checksum
85+
run: |
86+
cd artifacts
87+
for file in *; do shasum -a 256 "$file" >> checksum.txt; done
88+
89+
- name: Create Release
90+
id: create_release
91+
uses: softprops/action-gh-release@v2
92+
with:
93+
files: |
94+
./artifacts/*
95+
body_path: ./CHANGELOG.md
96+
draft: false

cmd/root.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ package cmd
66
import (
77
"Utkarsh4517/ginister/config"
88
"Utkarsh4517/ginister/controllers"
9+
"Utkarsh4517/ginister/docker"
910
"Utkarsh4517/ginister/models"
1011
"Utkarsh4517/ginister/routes"
12+
"Utkarsh4517/ginister/start"
1113
"bufio"
1214
"fmt"
1315
"os"
1416
"strings"
15-
"Utkarsh4517/ginister/docker"
17+
1618
"github.com/spf13/cobra"
1719
)
1820

@@ -53,6 +55,11 @@ func createProject(projectName string, reader *bufio.Reader) {
5355
fmt.Printf("Error creating Dockerfile: %v\n", err)
5456
}
5557

58+
err = start.CreateMainFile(projectName)
59+
if err != nil {
60+
fmt.Printf("Error creating main.go: %v\n", err)
61+
}
62+
5663
var modelNames []string
5764

5865
for {
@@ -98,4 +105,4 @@ func getModelFields(reader *bufio.Reader) []string {
98105
fields = append(fields, field)
99106
}
100107
return fields
101-
}
108+
}

config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ func ConnectDB() {
3333

3434
file.WriteString(content)
3535
fmt.Println("Config file created successfully!")
36-
}
36+
}

controllers/generateController.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ func Delete%s(c *gin.Context) {
4444

4545
file.WriteString(content)
4646
fmt.Printf("Controller for %s created successfully!\n", modelName)
47-
}
47+
}

docker/docker.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package docker
22

33
import (
4-
"fmt"
5-
"os"
4+
"fmt"
5+
"os"
66
)
77

88
func CreateDockerfile(projectDir string) error {
9-
content := `FROM golang:1.23
9+
content := `FROM golang:1.23
1010
1111
WORKDIR /app
1212
@@ -22,13 +22,13 @@ EXPOSE 8080
2222
CMD ["./main"]
2323
`
2424

25-
filePath := fmt.Sprintf("%s/Dockerfile", projectDir)
26-
file, err := os.Create(filePath)
27-
if err != nil {
28-
return err
29-
}
30-
defer file.Close()
25+
filePath := fmt.Sprintf("%s/Dockerfile", projectDir)
26+
file, err := os.Create(filePath)
27+
if err != nil {
28+
return err
29+
}
30+
defer file.Close()
3131

32-
_, err = file.WriteString(content)
33-
return err
32+
_, err = file.WriteString(content)
33+
return err
3434
}

main.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
/*
22
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3-
43
*/
54
package main
65

76
import (
87
"Utkarsh4517/ginister/cmd"
9-
108
)
119

1210
func main() {
1311
cmd.Execute()
1412
// config.ConnectDB()
1513
// router := routes.SetupRouter()
1614

17-
// router.Run(":8080")
15+
// router.Run(":8080")
1816
}

models/generateModel.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ func GenerateModelFile(projectName, modelName string, fields []string) {
2020

2121
file.WriteString(content)
2222
fmt.Printf("Model for %s created successfully!\n", modelName)
23-
}
23+
}

routes/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ func SetupRouter() *gin.Engine {
4040

4141
file.WriteString(content)
4242
fmt.Println("Routes file created successfully!")
43-
}
43+
}

start/main.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package start
2+
3+
import (
4+
"fmt"
5+
"os"
6+
)
7+
8+
func CreateMainFile(projectDir string) error {
9+
content := `package main
10+
11+
import (
12+
"github.com/gin-gonic/gin"
13+
)
14+
15+
func main() {
16+
r := gin.Default()
17+
18+
r.Run(":8080")
19+
}
20+
`
21+
22+
filePath := fmt.Sprintf("%s/main.go", projectDir)
23+
file, err := os.Create(filePath)
24+
if err != nil {
25+
return err
26+
}
27+
defer file.Close()
28+
29+
_, err = file.WriteString(content)
30+
return err
31+
}

0 commit comments

Comments
 (0)