Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Created August 20, 2021 06:10
Show Gist options
  • Save percybolmer/ebda0612ef6b344da0fae8b326ad77d7 to your computer and use it in GitHub Desktop.
Save percybolmer/ebda0612ef6b344da0fae8b326ad77d7 to your computer and use it in GitHub Desktop.
"NewService": {
"scope": "go",
"prefix": "NewService",
"body": [
"// Configuration is a alias for a function that takes a Service pointer and modifies it",
"type Configuration func(s *Service) error",
"",
"// Service is a struct that holds all repositories and combines logic",
"type Service struct {",
" //Add Repository fields here",
"}",
"",
"// New$1Service creates a new Service and accepts a variable amount of config functions",
"func New$1Service(configuration ...Configuration) *Service {",
" s := &Service{}",
" for _, cfg := range configuration{",
" if err := cfg(s); err != nil {",
" panic(err)",
" }",
" }",
" return s",
"}",
],
"description": "Creates a new Service with a Constructor function"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment