feat: add initial module and main functionality
This commit is contained in:
commit
5b8009d9e6
3 changed files with 42 additions and 0 deletions
3
go.mod
Normal file
3
go.mod
Normal file
|
@ -0,0 +1,3 @@
|
|||
module go-workshop
|
||||
|
||||
go 1.24.0
|
10
main.go
Normal file
10
main.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package main
|
||||
|
||||
import "go-workshop/test"
|
||||
|
||||
func main() {
|
||||
err := test.PrintString("")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
29
test/test.go
Normal file
29
test/test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CustomError represents my custom error
|
||||
type CustomError struct {
|
||||
Message string
|
||||
Code string
|
||||
}
|
||||
|
||||
// Error implements error.
|
||||
func (c CustomError) Error() string {
|
||||
return fmt.Sprintf("CustomError\nMessage: %s\nCode: %s\n", c.Message, c.Code)
|
||||
}
|
||||
|
||||
// PrintString prints a string when not empty
|
||||
func PrintString(str string) (err error) {
|
||||
if str == "" {
|
||||
return CustomError{
|
||||
Message: "Input is empty",
|
||||
Code: "some code",
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println(str)
|
||||
return
|
||||
}
|
Loading…
Add table
Reference in a new issue