Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Main; changed weaver.Run to take lambda. #409

Merged
merged 1 commit into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package weaver

import (
"context"
"crypto/tls"
"net"
"sync"
Expand Down Expand Up @@ -101,13 +100,7 @@ type component struct {
var _ Instance = &componentImpl{}

// Main is interface implemented by an application's main component.
// This component is instantiated and its Main() method called by
// `weaver.Run`.
type Main interface {
// Main contains the application main. It typically loops
// forever, e.g., inside http.Serve.
Main(context.Context) error
}
type Main interface{}

// Implements[T] is a type that can be embedded inside a component implementation
// struct to indicate that the struct implements a component of type T. E.g.,
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

func main() {
flag.Parse()
if err := weaver.Run(context.Background()); err != nil {
if err := weaver.Run(context.Background(), serve); err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion examples/chat/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type server struct {
chat weaver.Listener
}

func (s *server) Main(ctx context.Context) error {
func serve(ctx context.Context, s *server) error {
s.httpServer.Handler = instrument(s.label, s)
s.Logger().Debug("Chat service available", "address", s.chat)
return s.httpServer.Serve(s.chat)
Expand Down
93 changes: 2 additions & 91 deletions examples/chat/weaver_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/collatz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var localAddr = flag.String("local_addr", "localhost:9000", "Collatz server loca

func main() {
flag.Parse()
if err := weaver.Run(context.Background()); err != nil {
if err := weaver.Run(context.Background(), serve); err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion examples/collatz/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type server struct {
lis weaver.Listener `weaver:"collatz"`
}

func (s *server) Main(ctx context.Context) error {
func serve(ctx context.Context, s *server) error {
s.mux.Handle("/", weaver.InstrumentHandlerFunc("collatz", s.handle))
s.mux.HandleFunc(weaver.HealthzURL, weaver.HealthzHandler)
s.Logger().Debug("Collatz service available", "address", s.lis)
Expand Down
93 changes: 2 additions & 91 deletions examples/collatz/weaver_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/factors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
func main() {
flag.Parse()
ctx := context.Background()
if err := weaver.Run(ctx); err != nil {
if err := weaver.Run(ctx, serve); err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion examples/factors/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type server struct {
lis weaver.Listener `weaver:"factors"`
}

func (s *server) Main(ctx context.Context) error {
func serve(ctx context.Context, s *server) error {
http.Handle("/", weaver.InstrumentHandlerFunc("/", s.handleFactors))
s.Logger().Info("factors server running", "addr", s.lis)
return http.Serve(s.lis, nil)
Expand Down
Loading