Skip to content

Instantly share code, notes, and snippets.

View mayankcpdixit's full-sized avatar

Mayank mayankcpdixit

View GitHub Profile
@mayankcpdixit
mayankcpdixit / http_trailers.md
Last active March 30, 2019 10:58
Setting up http trailers in Golang

Setting up http trailers in Golang

  1. Trailers are of header type in go.
  2. You can only read trailer after reading body
package main

import (
	"io/ioutil"
	"log"
@mayankcpdixit
mayankcpdixit / route53-java-gradle.md
Last active December 12, 2018 06:50
Connect with AWS route 53 using Java(Spring) and gradle

Connect with AWS route 53 using Java(Spring) and gradle

Concept:

  1. We'll have env vars set
export AWS_ACCESS_KEY_ID="XXXXX"
export AWS_SECRET_KEY="XXXXX"
  1. We'll Use AmazonRoute53ClientBuilder to generate client object
  2. We'll import core sdk and route53 sdk
@mayankcpdixit
mayankcpdixit / spring-boot-kafka.md
Last active December 13, 2018 07:27
Getting started with SpringBoot and kafka
  1. Install Kafka and start zkServer and kafka-server
  2. Uncomment listeners & advertised.listerners in server.properties.
  3. SpringBoot App for kafka (sample)
  4. Run kafka in local
  5. gradle build this repo
  6. Start the app using: java -jar build/libs/spring-kafka-0.0.1-SNAPSHOT.jar
  7. Publish using http://localhost:8080/greetings?message=HelloManThisIsPublished
  8. Check terminal logs for publish and polling logs. Cheers!

App Directory structure. Download from git repo.

@mayankcpdixit
mayankcpdixit / install-kafka-mac.md
Last active April 19, 2022 02:25
Install Kafka in local (mac)

Install kafka in your local mac machine

run following commands:

brew install kafka
sudo mkdir -p /usr/local/var/run/zookeeper/data
sudo chmod 777 /usr/local/var/run/zookeeper/data
zkServer start

mkdir -p /usr/local/var/lib/kafka-logs
@mayankcpdixit
mayankcpdixit / sprint-boot-gradle-1-min.md
Last active December 10, 2018 06:36
Getting started with SpringBoot and Gradle

Spring boot and gradle. Get started in 1 min:

Dir structure of TestRepo:

├── build.gradle
└── src
    └── main
        └── java
            └── hello
                ├── Application.java
@mayankcpdixit
mayankcpdixit / grpc-gateway-custom-header.md
Created December 4, 2018 15:31
How to add custom headers in grpc-gateway

Adding custom header to grpc request

md1 := func(context.Context, *http.Request) metadata.MD {
  return metadata.New(map[string]string{
    "custom-header": "custom-value",
  })
}

mux := runtime.NewServeMux(runtime.WithMetadata(md1))
@mayankcpdixit
mayankcpdixit / grpc-gateway-with-docs.md
Last active November 30, 2018 10:55
Serving GRPC gateway and docs on same endpoint

Serving GRPC gateway and docs(swagger) on same endpoint

So idea is pretty simple:

  1. We'll create a new httpMux
  2. We'll serve runtimeMux on (/)
  3. We'll serve index.html (using fileserver) on (/docs/)
  4. We'll not forget succeeding "/" on /docs/

In action:

Modify the example pt. 6 in this way:

@mayankcpdixit
mayankcpdixit / proxy-server-with-tls.md
Last active April 23, 2021 13:25
Using TLS in grpc-gateway

Using TLS in grpc-gateway

In GRPC client

By default DialOption{grpc.WithInsecure()} is used in example. And as docs mention you just need to replace WithInsecure with transport creds.

//opts := []grpc.DialOption{grpc.WithInsecure()}
creds, _ := credentials.NewClientTLSFromFile("tls.crt", "")
opts := []grpc.DialOption{grpc.WithTransportCredentials(creds)}

In HTTP server