docs: add simple Go guide

Signed-off-by: Tanguy ⧓ Herrmann <tanguy@dagger.io>
This commit is contained in:
Tanguy ⧓ Herrmann
2022-04-13 16:30:28 +02:00
parent 3750422a55
commit f744996556
6 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
module dagger.io/testgreetci
go 1.17

View File

@@ -0,0 +1,7 @@
package greeting
import "fmt"
func Greeting(name string) string {
return fmt.Sprintf("Hi %s!", name)
}

View File

@@ -0,0 +1,13 @@
package greeting
import "testing"
func TestGreeting(t *testing.T) {
name := "Dagger Test"
expect := "Hi Dagger Test!"
value := Greeting(name)
if expect != value {
t.Fatalf("Hello(%s) = '%s', expected '%s'", name, value, expect)
}
}

View File

@@ -0,0 +1,16 @@
package main
import (
"fmt"
"os"
"dagger.io/testgreetci/greeting"
)
func main() {
name := os.Getenv("NAME")
if name == "" {
name = "John Doe"
}
fmt.Printf(greeting.Greeting(name))
}