Summary: Add simple CI pipelines to the greet project. Here we add CI pipelines for both Woodpecker and Dagger CI as we are currently interested in both technologies. Changes: - Add .woodpecker/woodpecker.yml - Updated LICENSE - Updated README.md - Fixed linting issues in greet.go - Created a new internal go module for CI/CD in internal/build - Moved the magefiles to internal/build/magefiles - Add dagger pipeline code
42 lines
669 B
Go
42 lines
669 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
type numberOfArgumentError struct {
|
|
length int
|
|
}
|
|
|
|
func (e numberOfArgumentError) Error() string {
|
|
return fmt.Sprintf("unexpected number of arguments passed to the greeter: want 0 or 1 argument, got %d", e.length)
|
|
}
|
|
|
|
func main() {
|
|
osArgs := os.Args[1:]
|
|
|
|
if err := greet(os.Stdout, osArgs); err != nil {
|
|
log.Fatalf("ERROR: %s.\n", err)
|
|
}
|
|
}
|
|
|
|
func greet(writer io.Writer, args []string) error {
|
|
var name string
|
|
|
|
if len(args) > 1 {
|
|
return numberOfArgumentError{length: len(args)}
|
|
}
|
|
|
|
if len(args) == 0 {
|
|
name = "World"
|
|
} else {
|
|
name = args[0]
|
|
}
|
|
|
|
fmt.Fprintf(writer, "Hello, %s!\n", name)
|
|
|
|
return nil
|
|
}
|