Skip to content

Commit

Permalink
interface{} to any.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1k1o committed Nov 25, 2023
1 parent ffeef5e commit a6169da
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions internal/policies/chromium/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var policiesJson string

func Generate(policies types.BrowserPolicyContent) (string, error) {
policiesTmpl := map[string]interface{}{}
policiesTmpl := map[string]any{}
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
return "", err
}
Expand All @@ -23,7 +23,7 @@ func Generate(policies types.BrowserPolicyContent) (string, error) {
// Extensions
//

ExtensionInstallForcelist := []interface{}{}
ExtensionInstallForcelist := []any{}
for _, e := range policies.Extensions {
URL := e.URL
if URL == "" {
Expand All @@ -36,7 +36,7 @@ func Generate(policies types.BrowserPolicyContent) (string, error) {
)
}

ExtensionInstallAllowlist := []interface{}{}
ExtensionInstallAllowlist := []any{}
for _, e := range policies.Extensions {
ExtensionInstallAllowlist = append(
ExtensionInstallAllowlist,
Expand All @@ -46,7 +46,7 @@ func Generate(policies types.BrowserPolicyContent) (string, error) {

policiesTmpl["ExtensionInstallForcelist"] = ExtensionInstallForcelist
policiesTmpl["ExtensionInstallAllowlist"] = ExtensionInstallAllowlist
policiesTmpl["ExtensionInstallBlocklist"] = []interface{}{"*"}
policiesTmpl["ExtensionInstallBlocklist"] = []any{"*"}

//
// Developer Tools
Expand Down
4 changes: 2 additions & 2 deletions internal/policies/chromium/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func Parse(policiesJson string) (*types.BrowserPolicyContent, error) {
policies := types.BrowserPolicyContent{}

policiesTmpl := map[string]interface{}{}
policiesTmpl := map[string]any{}
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
return nil, err
}
Expand All @@ -23,7 +23,7 @@ func Parse(policiesJson string) (*types.BrowserPolicyContent, error) {

if extensions, ok := policiesTmpl["ExtensionInstallForcelist"]; ok {
policies.Extensions = []types.BrowserPolicyExtension{}
for _, val := range extensions.([]interface{}) {
for _, val := range extensions.([]any) {
s := strings.Split(val.(string), ";")
url := ""
if len(s) > 1 {
Expand Down
14 changes: 7 additions & 7 deletions internal/policies/firefox/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var policiesJson string

func Generate(policies types.BrowserPolicyContent) (string, error) {
policiesTmpl := struct {
Policies map[string]interface{} `json:"policies"`
Policies map[string]any `json:"policies"`
}{}
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
return "", err
Expand All @@ -24,13 +24,13 @@ func Generate(policies types.BrowserPolicyContent) (string, error) {
// Extensions
//

ExtensionSettings := map[string]interface{}{}
ExtensionSettings["*"] = map[string]interface{}{
ExtensionSettings := map[string]any{}
ExtensionSettings["*"] = map[string]any{
"installation_mode": "blocked",
}

for _, e := range policies.Extensions {
ExtensionSettings[e.ID] = map[string]interface{}{
ExtensionSettings[e.ID] = map[string]any{
"install_url": e.URL,
"installation_mode": "force_installed",
}
Expand All @@ -48,18 +48,18 @@ func Generate(policies types.BrowserPolicyContent) (string, error) {
// Persistent Data
//

Preferences := policiesTmpl.Policies["Preferences"].(map[string]interface{})
Preferences := policiesTmpl.Policies["Preferences"].(map[string]any)
Preferences["browser.urlbar.suggest.history"] = policies.PersistentData
Preferences["places.history.enabled"] = policies.PersistentData
policiesTmpl.Policies["Preferences"] = Preferences
policiesTmpl.Policies["SanitizeOnShutdown"] = !policies.PersistentData

if policies.PersistentData {
policiesTmpl.Policies["Homepage"] = map[string]interface{}{
policiesTmpl.Policies["Homepage"] = map[string]any{
"StartPage": "previous-session",
}
} else {
policiesTmpl.Policies["Homepage"] = map[string]interface{}{
policiesTmpl.Policies["Homepage"] = map[string]any{
"StartPage": "homepage",
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/policies/firefox/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Parse(policiesJson string) (*types.BrowserPolicyContent, error) {
policies := types.BrowserPolicyContent{}

policiesTmpl := struct {
Policies map[string]interface{} `json:"policies"`
Policies map[string]any `json:"policies"`
}{}
if err := json.Unmarshal([]byte(policiesJson), &policiesTmpl); err != nil {
return nil, err
Expand All @@ -30,12 +30,12 @@ func Parse(policiesJson string) (*types.BrowserPolicyContent, error) {

if extensions, ok := policiesTmpl.Policies["ExtensionSettings"]; ok {
policies.Extensions = []types.BrowserPolicyExtension{}
for id, val := range extensions.(map[string]interface{}) {
for id, val := range extensions.(map[string]any) {
if id == "*" {
continue
}

data := val.(map[string]interface{})
data := val.(map[string]any)
url, _ := data["install_url"].(string)

policies.Extensions = append(
Expand Down
16 changes: 8 additions & 8 deletions internal/server/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type logformatter struct {
}

func (l *logformatter) NewLogEntry(r *http.Request) middleware.LogEntry {
req := map[string]interface{}{}
req := map[string]any{}

if reqID := middleware.GetReqID(r.Context()); reqID != "" {
req["id"] = reqID
Expand All @@ -32,7 +32,7 @@ func (l *logformatter) NewLogEntry(r *http.Request) middleware.LogEntry {
req["agent"] = r.UserAgent()
req["uri"] = fmt.Sprintf("%s://%s%s", scheme, r.Host, r.RequestURI)

fields := map[string]interface{}{}
fields := map[string]any{}
fields["req"] = req

return &logentry{
Expand All @@ -43,12 +43,12 @@ func (l *logformatter) NewLogEntry(r *http.Request) middleware.LogEntry {

type logentry struct {
logger zerolog.Logger
fields map[string]interface{}
errors []map[string]interface{}
fields map[string]any
errors []map[string]any
}

func (e *logentry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra interface{}) {
res := map[string]interface{}{}
func (e *logentry) Write(status, bytes int, header http.Header, elapsed time.Duration, extra any) {
res := map[string]any{}
res["time"] = time.Now().UTC().Format(time.RFC1123)
res["status"] = status
res["bytes"] = bytes
Expand All @@ -65,8 +65,8 @@ func (e *logentry) Write(status, bytes int, header http.Header, elapsed time.Dur
}
}

func (e *logentry) Panic(v interface{}, stack []byte) {
err := map[string]interface{}{}
func (e *logentry) Panic(v any, stack []byte) {
err := map[string]any{}
err["message"] = fmt.Sprintf("%+v", v)
err["stack"] = string(stack)

Expand Down
2 changes: 1 addition & 1 deletion internal/utils/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ func Color(str string) string {
return result + str[lastIndex:]
}

func Colorf(format string, a ...interface{}) string {
func Colorf(format string, a ...any) string {
return fmt.Sprintf(Color(format), a...)
}
2 changes: 1 addition & 1 deletion internal/utils/swal2.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Swal2Response(w http.ResponseWriter, body string) {
http.Error(w, err.Error(), 500)
}

err = tmpl.Execute(w, map[string]interface{}{
err = tmpl.Execute(w, map[string]any{
"Body": template.HTML(body),
})

Expand Down

0 comments on commit a6169da

Please sign in to comment.