This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# users svc | |
resource "google_cloud_run_service" "users-svc" { | |
name = "users-svc" | |
location = var.gcp_region | |
template { | |
spec { | |
containers { | |
image = var.users_app_image | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcp_project_id = "didil-api-gateway-demo" | |
gcp_region = "europe-west1" | |
users_app_image = "gcr.io/didil-api-gateway-demo/users:0.1.1" | |
locations_app_image = "gcr.io/didil-api-gateway-demo/locations:0.1.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// BuildRouter builds the router | |
func BuildRouter() (*chi.Mux, error) { | |
r := chi.NewRouter() | |
// the single route in our app (would need to be moved to a "handlers" package in a production app) | |
r.Get("/all", func(w http.ResponseWriter, r *http.Request) { | |
users := []User{ | |
User{ | |
ID: 1, | |
Name: "Mike", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<Protocol> { | |
Ok(Protocol { | |
connection: BufReader::new(TcpStream::connect(addr).await?), | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error[E0277]: the trait bound `A: async_std::net::addr::ToSocketAddrs` is not satisfied | |
--> src/client.rs:35:60 | |
| | |
35 | let protocol = protocol::Protocol::connect(addr)?; | |
| ^^^^ the trait `async_std::net::addr::ToSocketAddrs` is not implemented for `A` | |
| | |
::: src/protocol.rs:102:12 | |
| | |
102 | pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<Protocol> { | |
| ------- ------------- required by this bound in `protocol::Protocol::connect` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for { | |
kv, _, err := client.KV().Get(serviceKey, nil) | |
if err != nil { | |
log.Fatalf("kv acquire err: %v", err) | |
} | |
if kv != nil && kv.Session != "" { | |
// there is a leader | |
leaderHostname := string(kv.Value) | |
sendMsg(leaderHostname, msgID) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// wait for SIGINT or SIGTERM, clean up and exit | |
sigCh := make(chan os.Signal) | |
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) | |
<-sigCh | |
close(doneCh) | |
log.Printf("Destroying session and leaving ...") | |
_, err = client.Session().Destroy(sID, nil) | |
if err != nil { | |
log.Fatalf("session destroy err: %v", err) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for { | |
if !isLeader { | |
acquired, _, err := client.KV().Acquire(acquireKv, nil) | |
if err != nil { | |
log.Fatalf("kv acquire err: %v", err) | |
} | |
if acquired { | |
isLeader = true | |
log.Printf("I'm the leader !\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package api | |
import ( | |
"encoding/json" | |
"net/http" | |
"net/http/httptest" | |
"testing" | |
"github.com/didil/volusnap/pkg/models" | |
"github.com/stretchr/testify/assert" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package api | |
import ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"strconv" | |
"time" |