Project-related API operations
Use the DataHub Go SDK to create, delete, list, query, and update projects.
Create a project
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
comment |
string |
The description of the project. |
Errors
|
Error type |
Error code |
Description |
|
ResourceExistError |
|
The resource already exists. |
|
AuthorizationFailedError |
|
The Authorization signature failed to parse. Verify that your AccessKey ID is correct. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
|
InvalidParameterError |
|
The parameter is invalid. |
Sample code
func createProjet(dh datahub.DataHub, projectName string) {
if err := dh.CreateProject(projectName, "project comment"); err != nil {
fmt.Println("create project failed")
fmt.Println(err)
return
}
fmt.Println("create successful")
}
Delete a project
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
Errors
|
Error type |
Error code |
Description |
|
ResourceExistError |
|
The resource already exists. |
|
AuthorizationFailedError |
|
The Authorization signature failed to parse. Verify that your AccessKey ID is correct. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
|
InvalidParameterError |
|
The parameter is invalid. |
Sample code
func deleteProject(dh datahub.DataHub, projectName string) {
if err := dh.DeleteProject("123"); err != nil {
fmt.Println("delete project failed")
fmt.Println(err)
return
}
fmt.Println("delete project successful")
}
List projects
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
Response example
1. type ListProjectResult struct {
2. ProjectNames []string `json:"ProjectNames"`
3. }
Errors
|
Error type |
Error code |
Description |
|
AuthorizationFailedError |
|
The Authorization signature failed to parse. Verify that your AccessKey ID is correct. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
Sample code
func listProject(dh datahub.DataHub, projectName string) {
lp, err := dh.ListProject()
if err != nil {
fmt.Println("get project list failed")
fmt.Println(err)
return
}
fmt.Println("get project list successful")
for _, projectName := range lp.ProjectNames {
fmt.Println(projectName)
}
}
Query a project
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project |
Response example
type GetProjectResult struct {
CreateTime int64 `json:"CreateTime"`
LastModifyTime int64 `json:"LastModifyTime"`
Comment string `json"Comment"`
}
Errors
|
Error type |
Error code |
Description |
|
ResourceExistError |
|
The resource already exists. |
|
AuthorizationFailedError |
|
The Authorization signature failed to parse. Verify that your AccessKey ID is correct. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
|
InvalidParameterError |
|
The parameter is invalid. |
Sample code
func getProject(dh datahub.DataHub, projectName string) {
gp, err := dh.GetProject(projectName)
if err != nil {
fmt.Println("get project message failed")
fmt.Println(err)
return
}
fmt.Println("get project message successful")
fmt.Println(*gp)
}
Update a project
Parameters
|
Parameter |
Type |
Description |
|
projectName |
string |
The name of the project. |
|
comment |
string |
The description of the project. |
Errors
|
Error type |
Error code |
Description |
|
ResourceExistError |
|
The resource already exists. |
|
AuthorizationFailedError |
|
The Authorization signature failed to parse. Verify that your AccessKey ID is correct. |
|
DatahubClientError |
- |
The base class for all other exceptions. |
|
InvalidParameterError |
|
The parameter is invalid. |
Sample code
1. func updateProject(dh datahub.DataHub, projectName string) {
2. if err := dh.UpdateProject(projectName, "new project comment"); err != nil {
3. fmt.Println("update project comment failed")
4. fmt.Println(err)
5. return
6. }
7. fmt.Println("update project comment successful")
8. }