go-workshop/test/test.go

29 lines
498 B
Go

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: "Code 5",
}
}
fmt.Println(str)
return
}