- open-dev
- build web application golang
- link: https://github.com/ducnpdev/open-dev/tree/master/letgo
- source code in forder gin-web-framework
- read document vietnamese: https://github.com/ducnpdev/open-dev/blob/master/kafka/README_VI.md#consumer-advanced
- read document vietnamese: https://github.com/ducnpdev/open-dev/blob/master/kafka/README_VI.md#topic-advanced
- read article install kafka: https://github.com/ducnpdev/open-dev/tree/master/kafka
- read source: https://github.com/ducnpdev/golang-rabbitmq
- read article install redis: https://github.com/ducnpdev/open-dev/tree/master/redis
- read article lear more rate-limit: https://viblo.asia/p/golang-ratelimit-la-gi-su-dung-ByEZkn3qKQ0
- pub-sub code example: https://github.com/ducnpdev/open-dev/tree/master/redis/pubsub
- edit size of image from base64: https://github.com/ducnpdev/open-dev/tree/master/usecase#resize-image
- Handle context timeout: https://github.com/ducnpdev/open-dev/blob/master/usecase/context/timeout.go
- Encrypt Decrypt Data, code example: https://github.com/ducnpdev/open-dev/blob/master/usecase/rsa/REAME.md
- This is code example: https://github.com/ducnpdev/open-dev/blob/master/usecase/ecdsa/ecdsa.go
- source-code example:
- 7 pattern thiết yếu trong golang: https://github.com/ducnpdev/open-dev/tree/master/concurrency/patterns
- create sqs simple: https://github.com/ducnpdev/open-dev/tree/master/terraform/apps/sqs
- code example use aws textract identity: https://docs.aws.amazon.com/textract/index.html
- code: https://github.com/ducnpdev/open-dev/blob/master/aws/textract/main.go
- Demo simple lambda function: https://github.com/ducnpdev/open-dev/tree/master/aws/lambda
- Crud with postgres, link source: https://github.com/ducnpdev/open-dev/tree/master/aws/lambda/crud
- build docker images: https://aws.amazon.com/blogs/compute/migrating-aws-lambda-functions-from-the-go1-x-runtime-to-the-custom-runtime-on-amazon-linux-2/
- link code examle: https://github.com/ducnpdev/open-dev/tree/master/aws/s3
- Test simple of function return error: https://opendev.hashnode.dev/golang-test-performance-function-standard-1
- Test convert string to int of 3 function: https://opendev.hashnode.dev/golang-test-performance-function-standard-1
package main
import (
"context"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
)
func main() {
Reuse()
//
NonReuse()
}
// NonReuse, not reuse http
func NonReuse() {
// client trace to log whether the request's underlying tcp connection was re-used
clientTrace := &httptrace.ClientTrace{
GotConn: func(info httptrace.GotConnInfo) {
log.Printf("conn was reused: %t", info.Reused)
},
}
traceCtx := httptrace.WithClientTrace(context.Background(), clientTrace)
// 1st request
req, err := http.NewRequestWithContext(traceCtx, http.MethodGet, "http://example.com", nil)
if err != nil {
log.Fatal(err)
}
_, err = http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
// 2nd request
req, err = http.NewRequestWithContext(traceCtx, http.MethodGet, "http://example.com", nil)
if err != nil {
log.Fatal(err)
}
_, err = http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
}
// Reuse, reuse http client
func Reuse() {
var (
err error
)
// client trace to log whether the request's underlying tcp connection was re-used
clientTrace := &httptrace.ClientTrace{
GotConn: func(info httptrace.GotConnInfo) {
log.Printf("conn was reused: %t", info.Reused)
},
}
traceCtx := httptrace.WithClientTrace(context.Background(), clientTrace)
// 1st request
req, err := http.NewRequestWithContext(traceCtx, http.MethodGet, "http://example.com", nil)
if err != nil {
log.Fatal(err)
}
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
if _, err := io.Copy(ioutil.Discard, res.Body); err != nil {
log.Fatal(err)
}
res.Body.Close()
// 2nd request
req, err = http.NewRequestWithContext(traceCtx, http.MethodGet, "http://example.com", nil)
if err != nil {
log.Fatal(err)
}
_, err = http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
}
- convert file key and file pem to base64
- link: https://github.com/ducnpdev/open-dev/tree/master/tls/base64parse
- facebook: https://www.facebook.com/phucducdev/
- gmail: [email protected] or [email protected]
- linkedin: https://www.linkedin.com/in/phucducktpm/
- hashnode: https://hashnode.com/@OpenDev
- telegram: https://t.me/OpenDevGolang
If you like or are using this project to learn or start your solution, please give it a star. Thanks!