Apply go fmt

This commit is contained in:
Alex 2020-02-09 23:04:37 +01:00
parent fa96e61d75
commit a85ffdfc80
2 changed files with 44 additions and 45 deletions

View file

@ -1,12 +1,12 @@
package main package main
import ( import (
"regexp"
"strings"
"fmt" "fmt"
"html/template" "html/template"
"net/http" "net/http"
"regexp"
"sort" "sort"
"strings"
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -47,7 +47,6 @@ func (d EntryList) Less(i, j int) bool {
return d[i].DN < d[j].DN return d[i].DN < d[j].DN
} }
type AdminUsersTplData struct { type AdminUsersTplData struct {
Login *LoginStatus Login *LoginStatus
UserNameAttr string UserNameAttr string
@ -86,7 +85,7 @@ func handleAdminUsers(w http.ResponseWriter, r *http.Request) {
} }
type AdminGroupsTplData struct { type AdminGroupsTplData struct {
Login *LoginStatus Login *LoginStatus
GroupNameAttr string GroupNameAttr string
Groups EntryList Groups EntryList
} }
@ -113,7 +112,7 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
} }
data := &AdminGroupsTplData{ data := &AdminGroupsTplData{
Login: login, Login: login,
GroupNameAttr: config.GroupNameAttr, GroupNameAttr: config.GroupNameAttr,
Groups: EntryList(sr.Entries), Groups: EntryList(sr.Entries),
} }
@ -125,39 +124,39 @@ func handleAdminGroups(w http.ResponseWriter, r *http.Request) {
type AdminLDAPTplData struct { type AdminLDAPTplData struct {
DN string DN string
Path []PathItem Path []PathItem
Children []Child Children []Child
Props map[string]*PropValues Props map[string]*PropValues
HasMembers bool HasMembers bool
Members []EntryName Members []EntryName
HasGroups bool HasGroups bool
Groups []EntryName Groups []EntryName
Error string Error string
Success bool Success bool
} }
type EntryName struct { type EntryName struct {
DN string DN string
DisplayName string DisplayName string
} }
type Child struct { type Child struct {
DN string DN string
Identifier string Identifier string
DisplayName string DisplayName string
} }
type PathItem struct { type PathItem struct {
DN string DN string
Identifier string Identifier string
Active bool Active bool
} }
type PropValues struct { type PropValues struct {
Name string Name string
Values []string Values []string
Editable bool Editable bool
} }
@ -272,9 +271,9 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
// Build path // Build path
path := []PathItem{ path := []PathItem{
PathItem{ PathItem{
DN: config.BaseDN, DN: config.BaseDN,
Identifier: config.BaseDN, Identifier: config.BaseDN,
Active: dn == config.BaseDN, Active: dn == config.BaseDN,
}, },
} }
@ -283,9 +282,9 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
dn_last_attr := strings.Split(dn_split[0], "=")[0] dn_last_attr := strings.Split(dn_split[0], "=")[0]
for i := len_base_dn + 1; i <= len(dn_split); i++ { for i := len_base_dn + 1; i <= len(dn_split); i++ {
path = append(path, PathItem{ path = append(path, PathItem{
DN: strings.Join(dn_split[len(dn_split)-i:len(dn_split)], ","), DN: strings.Join(dn_split[len(dn_split)-i:len(dn_split)], ","),
Identifier: dn_split[len(dn_split)-i], Identifier: dn_split[len(dn_split)-i],
Active: i == len(dn_split), Active: i == len(dn_split),
}) })
} }
@ -328,8 +327,8 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} }
} }
props[name_lower] = &PropValues{ props[name_lower] = &PropValues{
Name: attr.Name, Name: attr.Name,
Values: attr.Values, Values: attr.Values,
Editable: editable, Editable: editable,
} }
} }
@ -361,7 +360,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} }
for _, memdn := range members_dn { for _, memdn := range members_dn {
members = append(members, EntryName{ members = append(members, EntryName{
DN: memdn, DN: memdn,
DisplayName: mapDnToName[memdn], DisplayName: mapDnToName[memdn],
}) })
} }
@ -392,7 +391,7 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
} }
for _, grpdn := range groups_dn { for _, grpdn := range groups_dn {
groups = append(groups, EntryName{ groups = append(groups, EntryName{
DN: grpdn, DN: grpdn,
DisplayName: mapDnToName[grpdn], DisplayName: mapDnToName[grpdn],
}) })
} }
@ -417,8 +416,8 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
children := []Child{} children := []Child{}
for _, item := range sr.Entries { for _, item := range sr.Entries {
children = append(children, Child{ children = append(children, Child{
DN: item.DN, DN: item.DN,
Identifier: strings.Split(item.DN, ",")[0], Identifier: strings.Split(item.DN, ",")[0],
DisplayName: item.GetAttributeValue("displayname"), DisplayName: item.GetAttributeValue("displayname"),
}) })
} }
@ -441,16 +440,16 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
templateAdminLDAP.Execute(w, &AdminLDAPTplData{ templateAdminLDAP.Execute(w, &AdminLDAPTplData{
DN: dn, DN: dn,
Path: path, Path: path,
Children: children, Children: children,
Props: props, Props: props,
HasMembers: len(members) > 0 || hasMembers, HasMembers: len(members) > 0 || hasMembers,
Members: members, Members: members,
HasGroups: len(groups) > 0 || hasGroups, HasGroups: len(groups) > 0 || hasGroups,
Groups: groups, Groups: groups,
Error: dError, Error: dError,
Success: dSuccess, Success: dSuccess,
}) })
} }
@ -458,11 +457,11 @@ func handleAdminLDAP(w http.ResponseWriter, r *http.Request) {
type CreateData struct { type CreateData struct {
SuperDN string SuperDN string
IdType string IdType string
IdValue string IdValue string
DisplayName string DisplayName string
StructuralObjectClass string StructuralObjectClass string
ObjectClass string ObjectClass string
Error string Error string
} }
@ -526,7 +525,7 @@ func handleAdminCreate(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
data.Error = err.Error() data.Error = err.Error()
} else { } else {
http.Redirect(w, r, "/admin/ldap/" + dn, http.StatusFound) http.Redirect(w, r, "/admin/ldap/"+dn, http.StatusFound)
} }
} }

10
main.go
View file

@ -15,8 +15,8 @@ import (
"strings" "strings"
"github.com/go-ldap/ldap/v3" "github.com/go-ldap/ldap/v3"
"github.com/gorilla/sessions"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/gorilla/sessions"
) )
type ConfigFile struct { type ConfigFile struct {
@ -25,7 +25,7 @@ type ConfigFile struct {
LdapServerAddr string `json:"ldap_server_addr"` LdapServerAddr string `json:"ldap_server_addr"`
LdapTLS bool `json:"ldap_tls"` LdapTLS bool `json:"ldap_tls"`
BaseDN string `json:"base_dn"` BaseDN string `json:"base_dn"`
UserBaseDN string `json:"user_base_dn"` UserBaseDN string `json:"user_base_dn"`
UserNameAttr string `json:"user_name_attr"` UserNameAttr string `json:"user_name_attr"`
GroupBaseDN string `json:"group_base_dn"` GroupBaseDN string `json:"group_base_dn"`
@ -55,7 +55,7 @@ func readConfig() ConfigFile {
SessionKey: base64.StdEncoding.EncodeToString(key_bytes), SessionKey: base64.StdEncoding.EncodeToString(key_bytes),
LdapServerAddr: "ldap://127.0.0.1:389", LdapServerAddr: "ldap://127.0.0.1:389",
LdapTLS: false, LdapTLS: false,
BaseDN: "dc=example,dc=com", BaseDN: "dc=example,dc=com",
UserBaseDN: "ou=users,dc=example,dc=com", UserBaseDN: "ou=users,dc=example,dc=com",
UserNameAttr: "uid", UserNameAttr: "uid",
GroupBaseDN: "ou=groups,dc=example,dc=com", GroupBaseDN: "ou=groups,dc=example,dc=com",
@ -238,7 +238,7 @@ type HomePageData struct {
Login *LoginStatus Login *LoginStatus
CanAdmin bool CanAdmin bool
CanInvite bool CanInvite bool
BaseDN string BaseDN string
} }
func handleHome(w http.ResponseWriter, r *http.Request) { func handleHome(w http.ResponseWriter, r *http.Request) {
@ -264,7 +264,7 @@ func handleHome(w http.ResponseWriter, r *http.Request) {
Login: login, Login: login,
CanAdmin: can_admin, CanAdmin: can_admin,
CanInvite: can_invite, CanInvite: can_invite,
BaseDN: config.BaseDN, BaseDN: config.BaseDN,
}) })
} }