Skip to content

Instantly share code, notes, and snippets.

@JustLinuxUser
Created January 27, 2025 02:32
Show Gist options
  • Save JustLinuxUser/625efff64b2083e05dc1e4aba2631882 to your computer and use it in GitHub Desktop.
Save JustLinuxUser/625efff64b2083e05dc1e4aba2631882 to your computer and use it in GitHub Desktop.
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