Skip to content

Instantly share code, notes, and snippets.

View shijuvar's full-sized avatar

Shiju Varghese shijuvar

View GitHub Profile
@shijuvar
shijuvar / main.go
Last active April 10, 2017 16:12
NATS Request-Reply Request
func main() {
// Create NATS server connection
natsConnection, _ := nats.Connect(nats.DefaultURL)
log.Println("Connected to " + nats.DefaultURL)
msg, err := natsConnection.Request("Discovery.OrderService", nil, 1000*time.Millisecond)
if err == nil && msg != nil {
orderServiceDiscovery := pb.ServiceDiscovery{}
err := proto.Unmarshal(msg.Data, &orderServiceDiscovery)
@shijuvar
shijuvar / order_test.go
Created January 30, 2017 10:42
Benchmarking Protocol Buffers, JSON and XML in Go.
// Benchmark testing to measure the performance of marshaling and unmarshaling of ProtoBuf, JSON and XML
package order
import (
"encoding/json"
"encoding/xml"
"testing"
"time"
"github.com/golang/protobuf/proto"
@shijuvar
shijuvar / main.go
Created October 11, 2016 09:24
The gRPC Client
package main
import (
"io"
"log"
"golang.org/x/net/context"
"google.golang.org/grpc"
pb "github.com/shijuvar/go-recipes/grpc/customer"
@shijuvar
shijuvar / main.go
Created October 11, 2016 08:20
A gRPC server
package main
import (
"log"
"net"
"strings"
"golang.org/x/net/context"
"google.golang.org/grpc"
@shijuvar
shijuvar / customer.pb.go
Last active October 11, 2016 08:13
Go source file generated by protoc compiler
// Code generated by protoc-gen-go.
// source: customer.proto
// DO NOT EDIT!
/*
Package customer is a generated protocol buffer package.
It is generated from these files:
customer.proto
@shijuvar
shijuvar / customer.proto
Created October 11, 2016 06:14
Service interface and the structure of the payload messages in Protocol Buffer
syntax = "proto3";
package customer;
// The Customer service definition.
service Customer {
// Get all Customers with filter - A server-to-client streaming RPC.
rpc GetCustomers(CustomerFilter) returns (stream CustomerRequest) {}
// Create a new Customer - A simple RPC
rpc CreateCustomer (CustomerRequest) returns (CustomerResponse) {}
@shijuvar
shijuvar / main.go
Created January 20, 2016 11:50
HTTP Server with http.HandleFunc
package main
import (
"fmt"
"log"
"net/http"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to Go Web Development")
@shijuvar
shijuvar / main.go
Created January 20, 2016 11:25
Using HandlerFunc type as the HTTP handler
package main
import (
"fmt"
"log"
"net/http"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to Go Web Development")
@shijuvar
shijuvar / main.go
Created January 20, 2016 10:07
HTTP Server with custom HTTP Handler
package main
import (
"fmt"
"log"
"net/http"
)
type indexHandler struct {
}
@shijuvar
shijuvar / handler.go
Created January 20, 2016 07:19
http.Handler interface
type Handler interface {
ServeHTTP(ResponseWriter, *Request)
}