-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a39a240
commit 17fd677
Showing
7 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package database | ||
|
||
var connection string | ||
|
||
func init() { | ||
connection = "MySQL" | ||
} | ||
|
||
func GetDatabase() string { | ||
return connection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
func Pembagian(nilai int, pembagi int) (int, error) { | ||
if pembagi == 0 { | ||
return 0, errors.New("Pembagian dengan NOL") | ||
} else { | ||
return nilai / pembagi, nil | ||
} | ||
} | ||
|
||
func main() { | ||
hasil, err := Pembagian(100, 2500) | ||
if err == nil { | ||
fmt.Println("Hasil ", hasil) | ||
} else { | ||
fmt.Println("Error ", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type validationErrr struct { | ||
Message string | ||
} | ||
|
||
func (v *validationErrr) Error() string { | ||
return v.Message | ||
} | ||
|
||
type notFoundError struct { | ||
Message string | ||
} | ||
|
||
func (n *notFoundError) Error() string { | ||
return n.Message | ||
} | ||
|
||
func SavedData(id string, data any) error { | ||
if id == "" { | ||
return &validationErrr{"valid error"} | ||
} | ||
|
||
if id != "didi" { | ||
return ¬FoundError{"not found"} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
err := SavedData("eko", nil) | ||
if err != nil { | ||
if validationErrr, ok := err.(*validationErrr); ok { | ||
fmt.Println("valid error", validationErrr.Error()) | ||
} else if notFoundError, ok := err.(*notFoundError); ok { | ||
fmt.Println("not found", notFoundError.Error()) | ||
} else { | ||
fmt.Println("unknown", err.Error()) | ||
} | ||
} else { | ||
fmt.Println("susses") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package helper | ||
|
||
import "fmt" | ||
|
||
var version = "1.0.0" | ||
var Application = "golang" | ||
|
||
func sayGoodBye(name string) string { | ||
return "goodbye " + name | ||
} | ||
|
||
func SayHello(name string) string { | ||
return "Helo " + name | ||
} | ||
|
||
func helper() { | ||
result := sayGoodBye("lesmana") | ||
fmt.Println(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"belajar-golang-dasar/helper" | ||
_ "belajar-golang-dasar/internal" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
result := helper.SayHello("Didi") | ||
fmt.Println(result) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"belajar-golang-dasar/database" | ||
"fmt" | ||
) | ||
|
||
func main() { | ||
fmt.Println(database.GetDatabase()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package internal | ||
|
||
import "fmt" | ||
|
||
func init() { | ||
fmt.Println("ini internal") | ||
} |