Skip to content

Commit

Permalink
restructure everything as modules and update git action
Browse files Browse the repository at this point in the history
  • Loading branch information
nptri committed Sep 20, 2024
1 parent b1415bd commit fe03596
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '^1.23.1'
- run: go run main.go
- run: go run main.go
working-directory: ./mainFolder
2 changes: 1 addition & 1 deletion custompackage.go → custompackage/custompackage.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package custompackage

func AddFunc(x int, y int) int {
return x+y
Expand Down
3 changes: 3 additions & 0 deletions custompackage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/custompackage

go 1.23.1
2 changes: 1 addition & 1 deletion ForLoop.go → examplepackage/ForLoop.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package examplepackage
import "fmt"
//Anonymous function with parameters
// var (
Expand Down
2 changes: 1 addition & 1 deletion IfCondition.go → examplepackage/IfCondition.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package examplepackage

import "fmt"

Expand Down
4 changes: 2 additions & 2 deletions advanceFunctions.go → examplepackage/advanceFunctions.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package examplepackage
import "fmt"
//Anonymous function with parameters
// var (
Expand All @@ -7,7 +7,7 @@ import "fmt"
// }
// )

func advanceFunctions() {
func AdvanceFunctions() {
// fmt.Println("area is:", area(5, 10))
fmt.Printf("Area is: %.1f",
func(coorX float32, coorY float32) (area float32) {
Expand Down
10 changes: 5 additions & 5 deletions functions.go → examplepackage/functions.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package main
package examplepackage

import (
"fmt"
)

//A simple function
func simpleFunction() {
func SimpleFunction() {
fmt.Println("hello world")
}
//A function with Params
func functionWithParameters(x int, y int) {
func FunctionWithParameters(x int, y int) {
total := 0
total = x + y
fmt.Println(total)
}
//A function with Types return
func functionWithTypes(x float32, y float32) float32 {
func FunctionWithTypes(x float32, y float32) float32 {
var total float32
total = x + y
return total
}
//A function with a return named value
func functionWithNamedValue(x float32, y float32) (area float32) {
func FunctionWithNamedValue(x float32, y float32) (area float32) {
area = x * y
return area
}
Expand Down
3 changes: 3 additions & 0 deletions examplepackage/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/examplepackage

go 1.23.1
4 changes: 2 additions & 2 deletions hello-world.go → examplepackage/hello-world.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main
package examplepackage

import "fmt"

func helloWorld() {
func HelloWorld() {
fmt.Println("hello world")
}
4 changes: 2 additions & 2 deletions pointers.go → examplepackage/pointers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package examplepackage

import (
"fmt"
)

func pointerProg() {
func PointerProg() {
//Declare a pointer
var PointerTo *int

Expand Down
4 changes: 2 additions & 2 deletions switchCase.go → examplepackage/switchCase.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main
package examplepackage

import (
"fmt"
)

func switchCase() {
func SwitchCase() {
// var today = time.Now()
var today = 20
switch today {
Expand Down
4 changes: 2 additions & 2 deletions typeCast.go → examplepackage/typeCast.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main
package examplepackage

import "fmt"

func typeCasting() {
func TypeCasting() {
valueToBeCasted := 15.221
fmt.Println("value has been casted to int type, value is:", int(valueToBeCasted))
}
4 changes: 2 additions & 2 deletions variables.go → examplepackage/variables.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package examplepackage

import (
"fmt"
Expand All @@ -7,7 +7,7 @@ import (

const s string = "constant"

func variablesName() {
func VariablesName() {
var a = "initial"
fmt.Println(a)

Expand Down
8 changes: 0 additions & 8 deletions main.go

This file was deleted.

12 changes: 12 additions & 0 deletions mainFolder/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module example.com/mainFolder

go 1.23.1

replace example.com/examplepackage => ../examplepackage

replace example.com/custompackage => ../custompackage

require (
example.com/custompackage v0.0.0-00010101000000-000000000000
example.com/examplepackage v0.0.0-00010101000000-000000000000
)
11 changes: 11 additions & 0 deletions mainFolder/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import cust "example.com/custompackage"
import custFunc "example.com/examplepackage"
import "fmt"

func main() {
fmt.Println(cust.AddFunc(1, 3))
custFunc.ForLoop()

}

0 comments on commit fe03596

Please sign in to comment.