Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
A journey of a thousand miles begins with a single step.

Pinku Deb Nath prantoran

🐢
A journey of a thousand miles begins with a single step.
View GitHub Profile
@prantoran
prantoran / main.go
Created May 26, 2019
graceful-server
View main.go
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
View synccondsimple.go
package main
import (
"fmt"
"os"
"os/signal"
"sync"
"time"
)
View modified-pubsub-client.go
jbts, err := json.Marshal(PubSubKey) // assuming the data of the json key is in the PubSubKey struct
if err != nil {
log.Println("could not convert api json to bytes:", err)
return
}
conf, err := google.JWTConfigFromJSON(jbts, "https://www.googleapis.com/auth/pubsub")
if err != nil {
log.Fatal(err)
}
ts := conf.TokenSource(ctx)
View gcpcloud-subscriber-simple.go
func main() {
pflag.String("subscription", "example-subscription", "name of subscriber")
pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
ctx := context.Background()
proj := "pubsubx-206305"
client, err := pubsub.NewClient(ctx, proj)
if err != nil {
log.Fatalf("Could not create pubsub Client: %v", err)
}
View gcpcloud-publish-simple.go
func main() {
ctx := context.Background()
proj := "pubsubx-206305"
client, err := pubsub.NewClient(ctx, proj)
if err != nil {
log.Fatalf("Could not create pubsub Client: %v", err)
}
const topic = "my-topic"
// Create a new topic called my-topic.
View main_test.go
package main
import (
"net/http"
"os"
"testing"
"github.com/prantoran/go-mock-microservice/mocks"
"github.com/prantoran/go-mock-microservice/printer"
)
View mocks.go
package mocks
import "github.com/prantoran/go-mock-microservice/printer"
type PrintFunc func(string) (*printer.Resp, error)
type MockPrinter struct {
MockPrintFunc PrintFunc
}
View printer.go
package printer
import (
"io/ioutil"
"net/http"
)
type Printer interface {
Print(s string) (*Resp, error)
}
You can’t perform that action at this time.