- My five years of go
- How-To: line/line-bot-sdk-go
-- Simple echo & face recognition chatbot
- Develop/test with ngrok
- Develop with docker-compose
- Deploy to Google Cloud Runbeta
- DevOps: Logging/Tracing/Metrics
• Simple echo & face recognition chatbot • Develop/test with ngrok • Develop with docker-compose • Deploy to Google Cloud Runbeta • DevOps 三寶: Logging/Tracing/Metrics
Linux. • The container listens for HTTP requests on the port defined by the PORT environment variable, which is always set to 8080. • Can fit in up to 2 GB of memory (initially 256MB). • Container instances must start an HTTP server within 4 minutes after receiving a request. • Default timeout: 5mins • Revision should work as containers are auto-scaled from 0 to multiple running instances. • When a revision does not receive any traffic, it is scaled down to zero instances • All computation is stateless and scoped to a request.
Service interface { Webhook(context.Context, interface{}) (int, error) ParseRequest(context.Context, *http.Request) (interface{}, error) } // Middleware describes a service (as opposed to endpoint) middleware. type Middleware func(Service) Service // LoggingMiddleware returns a service middleware that logs the // parameters and result of each method invocation. func LoggingMiddleware(logger Logger) Middleware { return func(next Service) Service { return loggingMiddleware{ logger: logger, next: next, } } }
"alansandbox", // MetricPrefix helps uniquely identify your metrics. MetricPrefix: "tracesim", }) if err != nil { log.Fatalf("Failed to create the Stackdriver exporter: %v", err) } // It is imperative to invoke flush before your main function exits defer sd.Flush() // Register it as a trace exporter trace.RegisterExporter(sd) app := cvbot.LoggingMiddleware(logger.New())(cvbot.NewCVApp()) app = cvbot.TraceMiddleware()(app) // setup trace config, production please use trace.ProbabilitySampler // Setup HTTP Server for receiving requests from LINE platform http.HandleFunc("/webhook", func(w http.ResponseWriter, req *http.Request) { ctx, span := trace.StartSpan(req.Context(), "webhook") defer span.End() events, err := app.ParseRequest(ctx, req)