Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] invalid character '-' in numeric literal. #96

Open
Priyal1995 opened this issue Mar 21, 2023 · 0 comments
Open

[BUG] invalid character '-' in numeric literal. #96

Priyal1995 opened this issue Mar 21, 2023 · 0 comments

Comments

@Priyal1995
Copy link

Describe the bug

I've recently switched the to go-micro v4 & started getting this error while using the function config.Load().

It was supposed to load the config instead I am getting this error -> invalid character '-' in numeric literal

How to reproduce the bug

func loadConfigFile() error {
	enc := yaml.NewEncoder()

	// Configmap Path
	configMapPath, set := common.GetEnvVar("CONFIGMAP_PATH", "./testdata", true)
	if !set {
		return common.GetErrEnvVar("CONFIGMAP_PATH")
	}
	// Configmap yaml file name
	configMapFile, set := common.GetEnvVar("CONFIGMAP_FILE", "data.yml", true)
	if !set {
		return common.GetErrEnvVar("CONFIGMAP_FILE")
	}
	// Secret Path
	secretPath, set := common.GetEnvVar("SECRET_PATH", "./testdata", true)
	if !set {
		return common.GetErrEnvVar("SECRET_PATH")
	}
	// Secret yaml file name
	secretFile, set := common.GetEnvVar("SECRET_FILE", "secrets.yml", true)
	if !set {
		return common.GetErrEnvVar("SECRET_FILE")
	}

	// Load config sources
	if err := config.Load(
		file.NewSource(
			file.WithPath(configMapPath+"/"+configMapFile),
			source.WithEncoder(enc)),
		file.NewSource(
			file.WithPath(secretPath+"/"+secretFile),
			source.WithEncoder(enc),
		)); err != nil {
		        fmt.Println(err)
		)
		return errLoadConfigFile
	}

	// Watch a value for changes
	watcher, err := config.Watch()
	if err != nil {
	       fmt.Println("Error 2!")
		)
		return errWatchFileError
	}

	go processConfig(watcher)
	return nil
}

Here's my sample struct file.

package structs

// Config structure that holds Configurations for Bot Components
type Config struct {
	Channels  []Channel `json:"channels"`
	Constants Constants `json:"constants"`
	Bot       Bot       `json:"tbot"`
	Views     []View    `json:"views"`
	// Secrets
	Readme  string `json:"README"`
	Project string `json:"project_id"`
}

type Channel struct {
	ID          string      `json:"id"`
	Bot         Bot         `json:"bot"`
	PagerDuty   PagerDuty   `json:"pagerduty"`
	XMatters    XMatters    `json:"xmatters"`
	Enps        Enps        `json:"enps"`
	IssueType   IssueType   `json:"issuetype"`
	Support     Support     `json:"support"`
	Suggestions Suggestions `json:"suggestions"`
	Core        string      `json:"core"`
	Views       []View      `json:"views"`
}

type Support struct {
	MessageOnly         bool          `json:"messageOnly"`
	IgnoreCode          string        `json:"ignorecode"`
	AckCode             string        `json:"ackcode"`
	ResolveCode         string        `json:"resolvecode"`
	ChannelsToJoin      []string      `json:"channelstojoin"`
	ResolveReactionName string        `json:"resolvereactionname"`
	MaximumMessages     int           `json:"maximummessages"`
	MessagesPerWarning  int           `json:"messagesperwarning"`
	CronConfig          []CronSetting `json:"cronconfig"`
	ThreadEmoji         string        `json:"threadEmoji"`
	NoOfMsgForHistory   int           `json:"noOfMsgForHistory"`
	RespondToHere       bool          `json:"respondToHere"`
	RespondToChannel    bool          `json:"respondToChannel"`
	SlashCommand        SlashCommand  `json:"slashCommand"`
}

type Suggestions struct {
	SlackSuggest           bool     `json:"slackSuggest"`        // Turns on Slack Suggestions for threads
	SearchChannelName      []string `json:"searchChannelName"`   // The channel names you want to search
	SearchChannelID        []string `json:"searchChannelID"`     // The channel ID's you want to search
	SearchMessageCount     []int    `json:"searchMessageCount"`  // The count for threads you want per channel
	Keywords               []string `json:"keywords"`            // The keywords you want to use for a custom message
	KeywordTemplateID      []string `json:"keywordTemplateID"`   // The template for the keywords for a custom message
	KeysForThreadSearch    []string `json:"keysForThreadSearch"` // The keywords for thread search
	ThreadSearchCharacters int      `json:"threadSearchCharacters"`
}

type SlashCommand struct {
	OnCall      string `json:"onCall"`
	MyOnCall    string `json:"myOnCall"`
	OpenTickets string `json:"openTickets"`
	TbotHelp    string `json:"tbotHelp"`
}

type PagerDuty struct {
	PagerDutyServiceID               string `json:"pagerdutyserviceid"`
	PagerDutyDefaultServiceID        string `json:"pagerdutydefaultserviceid"`
	PagerDutyIncidentUrgency         string `json:"pagerdutyincidenturgency"`
	PagerDutyIncidentDefaultUrgency  string `json:"pagerdutyincidentdefaulturgency"`
	PagerDutyIncidentPriority        string `json:"pagerdutyincidentpriority"`
	PagerDutyIncidentDefaultPriority string `json:"pagerdutyincidentdefaultpriority"`
	PagerDutyScheduleID              string `json:"pagerdutyscheduleid"`
	PagerDutyTeamID                  string `json:"pagerdutyteamid"`
}

type XMatters struct {
	HostName    string `json:"hostName"`
	GroupName   string `json:"groupID"`
	ServiceName string `json:"serviceName"`
	Severity    string `json:"severity"`
}

type Enps struct {
	Enable    bool   `json:"enable"`
	TableName string `json:"tableName"`
}

type IssueType struct {
	Enable    bool   `json:"enable"`
	TableName string `json:"tableName"`
}

// Bot structure that holds Configuration Bot Configuration
type Bot struct {
	Name           string `json:"name"`
	AppMention     string `json:"appmention"`
	ChannelName    string `json:"channelName"`
	IconURL        string `json:"iconurl"`
	EnableWebhooks bool   `json:"enablewebhooks"`
}

// Constants structure that holds constants
type Constants struct {
	Ack          string `json:"ack"`
	Resolve      string `json:"resolve"`
	Note         string `json:"note"`
	CreateTicket string `json:"create_ticket,omitempty"`
}

// View structure that holds view
type View struct {
	ID       string `json:"id"`
	Template string `json:"template"`
}

Here's the sample yaml file.

---
data:
    channels:
        - ID: "CHANNEL_ID"
          bot:
              appmention: "@bot"
              channelName: "#testing-channel"
              name: "bot"
              EnableWebhooks: false
          xmatters:
              HostName: "xmatters.com"
              GroupName: "xMatters-service" Test Team"
              ServiceName: "xMatters-service"
              Severity: ""
          support:
              IgnoreCode: ":tmobile:"
              NoOfMessageHistory: 0
              ThreadEmoji: "thread-please"
              slashCommand:
                  Help: "/slack-slash"
          suggestions:
              SlackSuggest: false
              ThreadSearchCharacters: 40
              SearchChannelName:
                  - "#slack-channel-name"
              SearchChannelID:
                  - "SOME_CHANNEL"
              SearchMessageCount:
                  - 1
          enps:
              enable: false
              tableName: "enps"
          issueType:
              enable: true
              tableName: "issueTeams"
          core: "support"
          views:
              - id: "welcome.json"
                template: |
                    {
                            "blocks": [
                                {
                                    "type": "section",
                                    "text": {
                                        "type": "mrkdwn",
                                        "text": "Hi <@{{ .User }}> :wave: Welcome to the Support Channel."
                                    }
                                },
                                {
                                    "type": "section",
                                    "text": {
                                        "type": "mrkdwn",
                                        "text": "Please select from the dropdown box and click submit! Then, please read the documentation before creating a ticket. Thank you!"
                                    }
                                }
                            ]
                    }

Environment

Go Version: please paste go version output here

GOVERSION="go1.19.5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant