ParseRequestData eg. "trustfile":"test:1,test2:2"

//ParseRequestData parse libdir trustfile eg. "trustfile":"test:1,test2:2"

func ParseRequestData(mapdata map[string]string, input string) bool {

    if !govalidator.IsNull(input) {

        if strings.Count(input, ":") == strings.Count(input, ",")+1 {

            sdata := strings.Split(input, ",")

            for _, n := range sdata {

                if !govalidator.IsNull(n) {

                    ndata := strings.Split(n, ":")

                    mapdata[ndata[0]] = ndata[1]

                } else {

                    return false

                }

            }

        } else {

            return false

        }

    }

    return true

}

    // trustfile {"test1:test1, test2:test2"}

    // libdirmapdata := make(map[string]string)

    // trustfilemapdata := make(map[string]string)

    // if !ParseRequestData(libdirmapdata, libdir) {

    //  return "", errno.ErrRequestData.Add(libdir)

    // }

    // if !ParseRequestData(trustfilemapdata, trustfile) {

    //  return "", errno.ErrRequestData.Add(trustfile)

    // }

 

你可能感兴趣的:(golang)