package pkg import ( "errors" "strings" ) // DNSLoggingProfile : High-speed logging settings for the DNS profile. type DNSLoggingProfile struct { ProfileCommon EnableQueryLogging string `json:"enable_query_logging"` IncludeCompleteAnswer string `json:"include_complete_answer"` IncludeSource string `json:"include_source"` IncludeView string `json:"include_view"` EnableResponseLogging string `json:"enable_response_logging"` IncludeQueryID string `json:"include_query_id"` IncludeTimestamp string `json:"include_timestamp"` LogPublisher string `json:"log_publisher"` } func ParseDNSLogging(raw string) (*DNSLoggingProfile, error) { p := new(DNSLoggingProfile) split := strings.Split(raw, "\n") if !strings.Contains(split[0], "dns-logging") { return nil, errors.New("not a dns-logging profile") } p.ProfileCommon = parseCommon(raw) for _, line := range split { f := strings.Fields(line) switch strings.ToLower(f[0]) { case "enable-query-logging": p.EnableQueryLogging = f[1] case "include-complete-answer": p.IncludeCompleteAnswer = f[1] case "include-source": p.IncludeSource = f[1] case "include-view": p.IncludeView = f[1] case "enable-response-logging": p.EnableResponseLogging = f[1] case "include-query-id": p.IncludeQueryID = f[1] case "include-timestamp": p.IncludeTimestamp = f[1] case "log-publisher": p.LogPublisher = strings.Join(f[1:], " ") } } return p, nil }