如何制作PHP';Golang的清洁入口功能是否有效?

如何制作PHP';Golang的清洁入口功能是否有效?,php,go,active-directory,ldap,Php,Go,Active Directory,Ldap,我试图从Golang的工作中获取cleanUpEntry函数,但不太确定如何制作映射(在PHP中,它是一个关联数组) 这是我在Golang中需要的cleanUpEntry的一个修改版本: function cleanUpEntry( $entry ) { $retEntry = array(); for ( $i = 0; $i < $entry["count"]; $i++ ) { if (is_array($entry[$i])) {

我试图从Golang的工作中获取cleanUpEntry函数,但不太确定如何制作映射(在PHP中,它是一个关联数组)

这是我在Golang中需要的cleanUpEntry的一个修改版本:

  function cleanUpEntry( $entry ) {
    $retEntry = array();
    for ( $i = 0; $i < $entry["count"]; $i++ ) {
      if (is_array($entry[$i])) {
        $subtree = $entry[$i];
        if ( ! empty($subtree['dn']) and ! isset($retEntry[$subtree['dn']])) {
          $retEntry[$subtree['dn']] = cleanUpEntry($subtree);
        }
        else {
          $retEntry[] = cleanUpEntry($subtree);
        }
      }
      else {
        $attribute = $entry[$i];
        //Converts the LDAP attributes to their proper bases
        if ( $entry[$attribute]['count'] == 1 ) {
          if($entry[$i]=="objectguid"){
            $retEntry[$attribute] = base64_encode($entry[$attribute][0]);
          }elseif($entry[$i]=="objectsid"){
            $retEntry[$attribute] = base64_encode($entry[$attribute][0]);
          }elseif($entry[$i]=="dnsrecord"){
            $retEntry[$attribute] = base64_encode($entry[$attribute][0]);
          }elseif($entry[$i]=="ipsecdata"){
            $retEntry[$attribute] = base64_encode($entry[$attribute][0]);
          }else{
            $retEntry[$attribute] = $entry[$attribute][0];
          }

        } else {
          for ( $j = 0; $j < $entry[$attribute]['count']; $j++ ) {
              $retEntry[$attribute][] = $entry[$attribute][$j];
          }
        }
      }
    }
    return $retEntry;
  }
func cleanUpEntry(result *ldap.SearchResult) {
  for _, entry := range result.Entries {
      for _, attr := range entry.Attributes {
        if attr.Name == "objectGUID"{
          //Convert objectGUID value to base 64.
          v := entry.GetAttributeValue("objectGUID")
          hello := base64.StdEncoding.EncodeToString([]byte(v))
          fmt.Println(hello)
        }else if attr.Name == "objectSid"{
          //Convert objectSid value to base 64.
          v := entry.GetAttributeValue("objectSid")
          hello := base64.StdEncoding.EncodeToString([]byte(v))
          fmt.Println(hello)
        }else if attr.Name == "ipsecData"{
          //Convert ipsecData value to base 64.
          v := entry.GetAttributeValue("ipsecData")
          hello := base64.StdEncoding.EncodeToString([]byte(v))
          fmt.Println(hello)
        }else if attr.Name == "dnsRecord"{
          //Convert dnsRecord value to base 64.
          v := entry.GetAttributeValue("dnsRecord")
          hello := base64.StdEncoding.EncodeToString([]byte(v))
          fmt.Println(hello)
        }else{
          for _, val := range 
entry.GetAttributeValues(attr.Name){
            fmt.Println(attr.Name, val)
            fmt.Printf("var7 = %T\n", val)
          }
        }
      }
      fmt.Println()
    }
}

我不太确定如何将其制作成三重嵌套的贴图,但它看起来是这样的:

注意**嵌套_数组[“DifferentizedName”]只是一个占位符,它将是可分辨名称的值,例如CN=test_user,DC=example,DC=com

    nested_array := make(map[string]map[string]map[interface{}]interface{})
    nested_array["distinguishedname"] = make(map[string]map[interface{}]interface{})
    nested_array["distinguishedname"]["objectClass"] = make(map[interface{}]interface{})
    nested_array["distinguishedname"]["objectClass"][0] = "top"
    nested_array["distinguishedname"]["objectClass"][1] = "shadowPosix"
    nested_array["distinguishedname"]["objectClass"][2] = "group"
当您执行fmt.Println(嵌套数组)时,将输出以下内容:

map[distinguishedname:map[objectClass:map[0:top 1:shadowPosix 2:group]]]