Should I preserve and reuse the created gclient.Client object?

Whether you create a gclient.Client object through g.Client or the gclient.New method, this object should be preserved and reused instead of creating a new Client object each time. This approach can improve efficiency, reduce resource usage, and be friendly to GC. The object has a built-in connection pool design that can effectively manage a large number of short connection requests. Due to the fact that the Client object does not consume a lot of resources, many people might not pay much attention to this point.

In what situations should I create a new gclient.Client object instead of reusing it? You can follow the decoupling design of business modules, where each business module manages its own gclient.Client object. Alternatively, when different scenarios require different configurations of the Client, you can create different Client objects to use.

invalid semicolon separator in query

Cause of the problem: By default, form requests containing the ; character are illegal (need urlencode). For details, please refer to the discussion: https://github.com/golang/go/issues/25192

Error Example:

  1. curl localhost:8000/Execute -d '{
  2. "Component": "mysql",
  3. "ResourceId": "cdb-gy6hm0ee",
  4. "Port": 6379,
  5. "SQL": "show databases;",
  6. "UserName": "root",
  7. "Password": ""
  8. }'

Corrected Example:

When submitting the request, you need to specify the ContentType; for example, here it should indicate a JSON request.

  1. curl -X POST -H "Content-Type: application/json" localhost:8000/Execute -d '{
  2. "Component": "mysql",
  3. "ResourceId": "cdb-gy6hm0ee",
  4. "Port": 6379,
  5. "SQL": "show databases;",
  6. "UserName": "root",
  7. "Password": ""
  8. }'