Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/devfeel/mapper
A simple and easy go tools for auto mapper struct to map, struct to struct, slice to slice, map to slice, map to json.
go get -u github.com/devfeel/mapper
Traditional Usage
package main
import (
"fmt"
"github.com/devfeel/mapper"
)
type (
User struct {
Name string
Age int
Id string `mapper:"_id"`
AA string `json:"Score"`
Time time.Time
}
Student struct {
Name string
Age int
Id string `mapper:"_id"`
Score string
}
Teacher struct {
Name string
Age int
Id string `mapper:"_id"`
Level string
}
)
func init() {
mapper.Register(&User{})
mapper.Register(&Student{})
}
func main() {
user := &User{}
userMap := &User{}
teacher := &Teacher{}
student := &Student{Name: "test", Age: 10, Id: "testId", Score: "100"}
valMap := make(map[string]interface{})
valMap["Name"] = "map"
valMap["Age"] = 10
valMap["_id"] = "x1asd"
valMap["Score"] = 100
valMap["Time"] = time.Now()
mapper.Mapper(student, user)
mapper.AutoMapper(student, teacher)
mapper.MapperMap(valMap, userMap)
fmt.Println("student:", student)
fmt.Println("user:", user)
fmt.Println("teacher", teacher)
fmt.Println("userMap:", userMap)
}
执行main,输出:
student: &{test 10 testId 100}
user: &{test 10 testId 100 0001-01-01 00:00:00 +0000 UTC}
teacher &{test 10 testId }
userMap: &{map 10 x1asd 100 2017-11-20 13:45:56.3972504 +0800 CST m=+0.006004001}
Object Usage
package main
import (
"fmt"
"github.com/devfeel/mapper"
)
type (
User struct {
Name string `json:"name" mapper:"name"`
Class int `mapper:"class"`
Age int `json:"age" mapper:"-"`
}
Student struct {
Name string `json:"name" mapper:"name"`
Class int `mapper:"class"`
Age []int `json:"age" mapper:"-"`
}
)
func main() {
user := &User{Name: "shyandsy", Class: 1, Age: 10}
student := &Student{}
// create mapper object
m := mapper.NewMapper()
// in the version < v0.7.8, we will use field name as key when mapping structs
// we keep it as default behavior in this version
m.SetEnableIgnoreFieldTag(true)
student.Age = []int{1}
// disable the json tag
m.SetEnabledJsonTag(false)
// student::age should be 1
m.Mapper(user, student)
fmt.Println("user:")
fmt.Println(user)
fmt.Println("student:")
fmt.Println(student)
}
执行main,输出:
user:
&{shyandsy 1 10}
student:
&{shyandsy 1 [1]}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.