not compatible with reflect.StructTag.Get

Remove the space after the comma before omitempty, then the error message will go away. bson:”password” json:”password,omitempty” (should be like this) In addition, this is a warning not an error. You should still be able to run your project.

How to verify JWT signature with JWK in Go?

Below is an example of JWT decoding and verification. It uses both the jwt-go and jwk packages: package main import ( “errors” “fmt” “github.com/dgrijalva/jwt-go” “github.com/lestrrat-go/jwx/jwk” ) const token = `eyJhbGciOiJSUzI1NiIsImtpZCI6Ind5TXdLNEE2Q0w5UXcxMXVvZlZleVExMTlYeVgteHlreW1ra1h5Z1o1T00ifQ.eyJzdWIiOiIwMHUxOGVlaHUzNDlhUzJ5WDFkOCIsIm5hbWUiOiJva3RhcHJveHkgb2t0YXByb3h5IiwidmVyIjoxLCJpc3MiOiJodHRwczovL2NvbXBhbnl4Lm9rdGEuY29tIiwiYXVkIjoidlpWNkNwOHJuNWx4ck45YVo2ODgiLCJpYXQiOjE0ODEzODg0NTMsImV4cCI6MTQ4MTM5MjA1MywianRpIjoiSUQuWm9QdVdIR3IxNkR6a3RUbEdXMFI4b1lRaUhnVWg0aUotTHo3Z3BGcGItUSIsImFtciI6WyJwd2QiXSwiaWRwIjoiMDBveTc0YzBnd0hOWE1SSkJGUkkiLCJub25jZSI6Im4tMFM2X1d6QTJNaiIsInByZWZlcnJlZF91c2VybmFtZSI6Im9rdGFwcm94eUBva3RhLmNvbSIsImF1dGhfdGltZSI6MTQ4MTM4ODQ0MywiYXRfaGFzaCI6Im1YWlQtZjJJczhOQklIcV9CeE1ISFEifQ.OtVyCK0sE6Cuclg9VMD2AwLhqEyq2nv3a1bfxlzeS-bdu9KtYxcPSxJ6vxMcSSbMIIq9eEz9JFMU80zqgDPHBCjlOsC5SIPz7mm1Z3gCwq4zsFJ-2NIzYxA3p161ZRsPv_3bUyg9B_DPFyBoihgwWm6yrvrb4rmHXrDkjxpxCLPp3OeIpc_kb2t8r5HEQ5UBZPrsiScvuoVW13YwWpze59qBl_84n9xdmQ5pS7DklzkAVgqJT_NWBlb5uo6eW26HtJwHzss7xOIdQtcOtC1Gj3O82a55VJSQnsEEBeqG1ESb5Haq_hJgxYQnBssKydPCIxdZiye-0Ll9L8wWwpzwig` const jwksURL = `https://companyx.okta.com/oauth2/v1/keys` func getKey(token *jwt.Token) (interface{}, error) { // TODO: cache response so we don’t have to make a request every time // … Read more

Go: convert strings in array to integer

You will have to loop through the slice indeed. If the slice only contains integers, no need of ParseFloat, Atoi is sufficient. import “fmt” import “strconv” func main() { var t = []string{“1”, “2”, “3”} var t2 = []int{} for _, i := range t { j, err := strconv.Atoi(i) if err != nil { … Read more

Go language how detect file changing?

Here’s a simple cross-platform version: func watchFile(filePath string) error { initialStat, err := os.Stat(filePath) if err != nil { return err } for { stat, err := os.Stat(filePath) if err != nil { return err } if stat.Size() != initialStat.Size() || stat.ModTime() != initialStat.ModTime() { break } time.Sleep(1 * time.Second) } return nil } And … Read more

How to check if an object has a particular method?

A simple option is to declare an interface with just the method you want to check for and then do a type assert against your type like; i, ok := myInstance.(InterfaceImplementingThatOneMethodIcareAbout) // inline iface declaration example i, ok = myInstance.(interface{F()}) You likely want to use the reflect package if you plan to do anything too … Read more