Skip to content

Commit

Permalink
chore(allsrv): add simple server daemon for allsrv
Browse files Browse the repository at this point in the history
To run the daemon run the following from the root of the git repo:

```shell
go run ./allsrv/cmd/allsrv
```

A sample query to get started:

```shell
curl -u admin:pass -H 'Content-Type: application/json' -X POST http://localhost:8091/v1/foos --json '{"data":{"type":"foo","attributes":{"name":"the first","note":"a note"}}}'
```

Play around with the daemon. Hit both v1 and v2 APIs. How do the
two `Server` versions compare?

Now that we have a sample server up and running, let's discuss what it
looks like to start moving on from the original mess.

The first thing we need to do is start communicating our intent to deprecate,
and eventually sunset the original APIs. I can't stress this enough,
**communication is key**. It should be everywhere and EXTREMELY obvious. In
the code, you can add deprecation/sunset headers.

Let's start there, go on and add deprecation headers to ALL the original
endpoints.
  • Loading branch information
jsteenb2 committed Jul 7, 2024
1 parent 28b32e1 commit 280ab07
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions allsrv/cmd/allsrv/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"log"
"net/http"
"os"

"github.com/jsteenb2/mess/allsrv"
)

func main() {
db := new(allsrv.InmemDB)

var svr http.Handler
switch os.Getenv("ALLSRV_SERVER") {
case "v1":
log.Println("starting v1 server")
svr = allsrv.NewServer(db, allsrv.WithBasicAuth("admin", "pass"))
case "v2":
log.Println("starting v2 server")
svr = allsrv.NewServerV2(db, allsrv.WithBasicAuthV2("admin", "pass"))
default: // run both
log.Println("starting combination v1/v2 server")
mux := http.NewServeMux()
allsrv.NewServer(db, allsrv.WithMux(mux), allsrv.WithBasicAuth("admin", "pass"))
allsrv.NewServerV2(db, allsrv.WithMux(mux), allsrv.WithBasicAuthV2("admin", "pass"))
svr = mux
}

port := ":8091"
log.Println("listening at http://localhost" + port)
if err := http.ListenAndServe(port, svr); err != nil && err != http.ErrServerClosed {
log.Println(err.Error())
os.Exit(1)
}
}

0 comments on commit 280ab07

Please sign in to comment.