This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"time" | |
"github.com/aws/aws-lambda-go/lambda" | |
"github.com/aws/aws-sdk-go/aws/request" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/prozz/aws-embedded-metrics-golang/emf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"net/http" | |
"time" | |
"github.com/aws/aws-lambda-go/lambda" | |
"github.com/prozz/aws-embedded-metrics-golang/emf" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Companion code for the Linux terminals blog series: https://dev.to/napicella/linux-terminals-tty-pty-and-shell-192e | |
// I have simplified the code to highlight the interesting bits for the purpose of the blog post: | |
// - windows resizing is not addressed | |
// - client does not catch signals (CTRL + C, etc.) to gracefully close the tcp connection | |
// | |
// Build: go build -o remote main.go | |
// In one terminal run: ./remote -server | |
// In another terminal run: ./remote | |
// | |
// Run on multiple machines: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package functiontype | |
import "fmt" | |
type Greeting func(name string) string | |
func GreetingService(request Request, greeting Greeting) string { | |
return fmt.Sprintf("Service says: %s", greeting(request.user)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context("Greeting with no Name option", func() { | |
It("returns default greeting", func() { | |
greeting := NewGreeting() | |
Expect(greeting.get()).To(Equal("Hello Stranger")) | |
}) | |
}) | |
Context("Greeting with Name option", func() { | |
It("returns custom greeting", func() { | |
greeting := NewGreeting(Name("Mickey")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Context("User present", func() { | |
var greeting string | |
MaybeUser(getUser(1)).IfPresent(func(u *User) { | |
greeting = "Hello " + u.name | |
}) | |
It("greets the user", func() { | |
Expect(greeting).To(Equal("Hello Mickey")) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Package constants shows a pattern to group constants together | |
package constants | |
// Endpoint contains the endpoint configuration | |
var Endpoint struct { | |
Hostname string | |
Port int | |
} | |
func init() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chain | |
import "fmt" | |
func ExampleChain() { | |
endpoint, _ := chain( | |
loadEndpointFromConfigFile, | |
loadEndpointFromEnvVariables, | |
loadEndpointFromDatabase, | |
).get() |