gunli commented on code in PR #11872:
URL: https://github.com/apache/inlong/pull/11872#discussion_r2101491198


##########
inlong-sdk/dataproxy-sdk-twins/dataproxy-sdk-golang/util/id.go:
##########
@@ -29,12 +29,14 @@ var (
 )
 
 func init() {
+       var id uint32 = 0
+
+       // Generate the ID from an IP if possible.
        ip, err := GetOneIP()
-       if err != nil {
-               log.Fatal(err)

Review Comment:
   Since we do not use SnowFlakeID as the batchID any more, I think do not 
panic here is acceptable, but I think it is better to let the user know why it 
fails, may be we can update it like this:
   ```
   func init() {
        ip, err := GetOneIP()
        if err != nil {
                log.Println("get local ip failed, stop to init snowflake")
                   return
        }
   
        id := IPtoUInt(ip)
        snowflakeNode, err = snowflake.NewNode(int64(id % 1024))
        if err != nil {
                log.Println("init snowflake failed, you can not use snowflake 
id generator further")
        }
   }
   
   func SnowFlakeID() (string, error) {
        if snowflakeNode == nil {
                return "", errors.New("snowflake is not initialized")
        }
        return snowflakeNode.Generate().String(), nil
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to