feat: add initial module and main functionality

This commit is contained in:
Jan K9f 2025-03-04 15:39:20 +01:00
commit 5b8009d9e6
Signed by: jank
GPG key ID: 22BEAC760B3333D6
3 changed files with 42 additions and 0 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module go-workshop
go 1.24.0

10
main.go Normal file
View 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
View 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
}