Created
January 27, 2025 02:32
-
-
Save JustLinuxUser/625efff64b2083e05dc1e4aba2631882 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
"github.com/gorilla/schema" | |
) | |
type TestStruct struct { | |
Time time.Time | |
} | |
func main() { | |
var test_struct TestStruct | |
hashmap := make(map[string][]string) | |
hashmap["Time"] = []string{""} | |
new_hashmap := make(map[string][]string) | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
// If we filter the "", it works perfectly, and applies the default value, like it should | |
for k, v := range hashmap { | |
if len(v) <= 1 && v[0] == "" { | |
continue; | |
} | |
new_hashmap[k] = v | |
} | |
var decoder = schema.NewDecoder() | |
err := decoder.Decode(&test_struct, new_hashmap); | |
if err != nil { | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment