Skip to content

Instantly share code, notes, and snippets.

@ak-ymst
Created March 28, 2019 07:44
Show Gist options
  • Save ak-ymst/b420efce93d293263305b32a662bf17f to your computer and use it in GitHub Desktop.
Save ak-ymst/b420efce93d293263305b32a662bf17f to your computer and use it in GitHub Desktop.
// see https://qiita.com/weloan/items/56f1c7792088b5ede136
package main
import (
"fmt"
)
type Server struct {
timeout int
address string
port int
}
func (server *Server) Call() {
fmt.Printf("Call To %s:%d with %d sec timeout \n", server.address, server.port, server.timeout);
}
type Option func(*Server)Option
func NewServerWithOptions(options ...Option) *Server {
var server = &Server{}
for _, option := range options {
option(server)
}
return server
}
func NewServer(timeout int, address string, port int) *Server {
return &Server {
timeout: timeout,
address: address,
port: port,
}
}
func main() {
var server = NewServer(30, "localhost", 25)
server.Call()
test("囁き", "詠唱", "念じろ!")
}
func test(words ...string) {
for _, word := range words {
fmt.Printf("%s \n", word)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment