Skip to content

Commit

Permalink
all: Fix duplicate [start:..] markers
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinav committed Aug 27, 2024
1 parent f6ef7fd commit f24c4fe
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
18 changes: 9 additions & 9 deletions docs/ex/get-started/02-http-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ import (
"go.uber.org/fx"
)

// --8<-- [start:provide-server]
// --8<-- [start:provide-server-1]
func main() {
// --8<-- [start:app]
fx.New(
fx.Provide(NewHTTPServer),
// --8<-- [end:provide-server]
// --8<-- [end:provide-server-1]
fx.Invoke(func(*http.Server) {}),
// --8<-- [start:provide-server]
// --8<-- [start:provide-server-2]
).Run()
// --8<-- [end:app]
}

// --8<-- [end:provide-server]
// --8<-- [end:provide-server-2]

// --8<-- [start:partial]
// --8<-- [start:partial-1]

// NewHTTPServer builds an HTTP server that will begin serving requests
// when the Fx application starts.
// --8<-- [start:full]
func NewHTTPServer(lc fx.Lifecycle) *http.Server {
srv := &http.Server{Addr: ":8080"}
// --8<-- [end:partial]
// --8<-- [end:partial-1]
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
ln, err := net.Listen("tcp", srv.Addr)
Expand All @@ -65,9 +65,9 @@ func NewHTTPServer(lc fx.Lifecycle) *http.Server {
return srv.Shutdown(ctx)
},
})
// --8<-- [start:partial]
// --8<-- [start:partial-2]
return srv
}

// --8<-- [end:partial]
// --8<-- [start:full]
// --8<-- [end:partial-2]
// --8<-- [end:full]
8 changes: 4 additions & 4 deletions docs/ex/get-started/03-echo-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import (
func main() {
fx.New(
// --8<-- [start:provides]
// --8<-- [start:provide-handler]
// --8<-- [start:provide-handler-1]
fx.Provide(
NewHTTPServer,
// --8<-- [end:provide-handler]
// --8<-- [end:provide-handler-1]
NewServeMux,
// --8<-- [start:provide-handler]
// --8<-- [start:provide-handler-2]
NewEchoHandler,
),
// --8<-- [end:provides]
fx.Invoke(func(*http.Server) {}),
// --8<-- [end:provide-handler]
// --8<-- [end:provide-handler-2]
).Run()
}

Expand Down
8 changes: 4 additions & 4 deletions docs/ex/get-started/04-logger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,20 @@ func NewServeMux(echo *EchoHandler) *http.ServeMux {

// EchoHandler is an http.Handler that copies its request body
// back to the response.
// --8<-- [start:echo-init]
// --8<-- [start:echo-init-1]
type EchoHandler struct {
log *zap.Logger
}

// --8<-- [end:echo-init]
// --8<-- [end:echo-init-1]

// NewEchoHandler builds a new EchoHandler.
// --8<-- [start:echo-init]
// --8<-- [start:echo-init-2]
func NewEchoHandler(log *zap.Logger) *EchoHandler {
return &EchoHandler{log: log}
}

// --8<-- [end:echo-init]
// --8<-- [end:echo-init-2]

// ServeHTTP handles an HTTP request to the /echo endpoint.
// --8<-- [start:echo-serve]
Expand Down
20 changes: 10 additions & 10 deletions docs/ex/get-started/06-another-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,23 @@ func main() {
fx.ParamTags(`name:"echo"`, `name:"hello"`),
),
// --8<-- [end:mux-provide]
// --8<-- [start:hello-provide-partial]
// --8<-- [start:hello-provide-partial-1]
// --8<-- [start:route-provides]
fx.Annotate(
NewEchoHandler,
fx.As(new(Route)),
// --8<-- [end:hello-provide-partial]
// --8<-- [end:hello-provide-partial-1]
fx.ResultTags(`name:"echo"`),
// --8<-- [start:hello-provide-partial]
// --8<-- [start:hello-provide-partial-2]
),
fx.Annotate(
NewHelloHandler,
fx.As(new(Route)),
// --8<-- [end:hello-provide-partial]
// --8<-- [end:hello-provide-partial-2]
fx.ResultTags(`name:"hello"`),
// --8<-- [start:hello-provide-partial]
// --8<-- [start:hello-provide-partial-3]
),
// --8<-- [end:hello-provide-partial]
// --8<-- [end:hello-provide-partial-3]
// --8<-- [end:route-provides]
zap.NewExample,
),
Expand Down Expand Up @@ -108,15 +108,15 @@ func NewHelloHandler(log *zap.Logger) *HelloHandler {

// Pattern reports the pattern under which
// this handler should be registered.
// --8<-- [start:hello-methods]
// --8<-- [start:hello-methods-1]
func (*HelloHandler) Pattern() string {
return "/hello"
}

// --8<-- [end:hello-methods]
// --8<-- [end:hello-methods-1]

// ServeHTTP handles an HTTP request to the /hello endpoint.
// --8<-- [start:hello-methods]
// --8<-- [start:hello-methods-2]
func (h *HelloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
Expand All @@ -132,7 +132,7 @@ func (h *HelloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

// --8<-- [end:hello-methods]
// --8<-- [end:hello-methods-2]

// EchoHandler is an http.Handler that copies its request body
// back to the response.
Expand Down
2 changes: 1 addition & 1 deletion docs/ex/value-groups/consume/annotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ var EmitterFromModule = fx.Options(
// EmitterFrom builds an Emitter from the list of watchers.
// --8<-- [start:new-variadic]
func EmitterFrom(watchers ...Watcher) (*Emitter, error) {
// --8<-- [start:new-variadic]
// --8<-- [end:new-variadic]
return &Emitter{ws: watchers}, nil
}
7 changes: 5 additions & 2 deletions docs/src/get-started/another-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Let's add another.
2. Implement the `Route` interface for this handler.

```go
--8<-- "get-started/06-another-handler/main.go:hello-methods"
--8<-- "get-started/06-another-handler/main.go:hello-methods-1"
--8<-- "get-started/06-another-handler/main.go:hello-methods-2"
```

The handler reads its request body,
Expand All @@ -21,7 +22,9 @@ Let's add another.
3. Provide this to the application as a `Route` next to `NewEchoHandler`.

```go
--8<-- "get-started/06-another-handler/main.go:hello-provide-partial"
--8<-- "get-started/06-another-handler/main.go:hello-provide-partial-1"
--8<-- "get-started/06-another-handler/main.go:hello-provide-partial-2"
--8<-- "get-started/06-another-handler/main.go:hello-provide-partial-3"
```

4. Run the application--the service will fail to start.
Expand Down
3 changes: 2 additions & 1 deletion docs/src/get-started/echo-handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Let's fix that.
Provide this to the application.

```go
--8<-- "get-started/03-echo-handler/main.go:provide-handler"
--8<-- "get-started/03-echo-handler/main.go:provide-handler-1"
--8<-- "get-started/03-echo-handler/main.go:provide-handler-2"
```

2. Next, write a function that builds an `*http.ServeMux`.
Expand Down
6 changes: 4 additions & 2 deletions docs/src/get-started/http-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Let's add an HTTP server to it.
1. Write a function to build your HTTP server.

```go
--8<-- "get-started/02-http-server/main.go:partial"
--8<-- "get-started/02-http-server/main.go:partial-1"
--8<-- "get-started/02-http-server/main.go:partial-2"
```

This isn't enough, though--we need to tell Fx how to start the HTTP server.
Expand All @@ -23,7 +24,8 @@ Let's add an HTTP server to it.
3. Provide this to your Fx application above with `fx.Provide`.

```go
--8<-- "get-started/02-http-server/main.go:provide-server"
--8<-- "get-started/02-http-server/main.go:provide-server-1"
--8<-- "get-started/02-http-server/main.go:provide-server-2"
```

4. Run the application.
Expand Down
3 changes: 2 additions & 1 deletion docs/src/get-started/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ but you should be able to use any logging system.
and in `NewEchoHandler` add a new logger argument to set this field.

```go
--8<-- "get-started/04-logger/main.go:echo-init"
--8<-- "get-started/04-logger/main.go:echo-init-1"
--8<-- "get-started/04-logger/main.go:echo-init-2"
```

3. In the `EchoHandler.ServeHTTP` method,
Expand Down

0 comments on commit f24c4fe

Please sign in to comment.