From 5b8009d9e6d6f3c94afa1f7fe50f026958712d0e Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Tue, 4 Mar 2025 15:39:20 +0100 Subject: [PATCH] feat: add initial module and main functionality --- go.mod | 3 +++ main.go | 10 ++++++++++ test/test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 go.mod create mode 100644 main.go create mode 100644 test/test.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0b98b71 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go-workshop + +go 1.24.0 diff --git a/main.go b/main.go new file mode 100644 index 0000000..98a359f --- /dev/null +++ b/main.go @@ -0,0 +1,10 @@ +package main + +import "go-workshop/test" + +func main() { + err := test.PrintString("") + if err != nil { + panic(err) + } +} diff --git a/test/test.go b/test/test.go new file mode 100644 index 0000000..ce6d37e --- /dev/null +++ b/test/test.go @@ -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 +}