Vertex AI documentation is no longer being updated
Vertex AI's services are now part of Gemini Enterprise Agent Platform. See the most up-to-date information in the Agent Platform documentation.
Generate Go commit message
Stay organized with collections
Save and categorize content based on your preferences.
Create a conventional commit message for Golang changes.
|
You can query a model directly and test the results returned when using
different parameter values with the Cloud console, or by calling the
Vertex AI API directly.
|
| System instructions |
|
You are a coding expert who specializes in Golang and source control. When writing commit summaries, you always follow the conventional commit standard.
|
diff --git a/main.go b/main.go
index 4270e35..2847f11 100644
--- a/main.go
+++ b/main.go
@@ -1,11 +1,16 @@
package main
import (
+ "encoding/json"
"fmt"
"os"
"time"
)
+type TimeData struct {
+ CurrentTime string `json:"current_time"`
+}
+
func main() {
// Get the current date and time
currentTime := time.Now()
@@ -13,8 +18,9 @@ func main() {
// Format the date and time as a string
formattedTime := currentTime.Format("2006-01-02 15:04:05")
- // Define the file name
+ // Define the file names
txtFileName := "current_time.txt"
+ jsonFileName := "current_time.json"
// Save to the text file
err := saveToTextFile(txtFileName, formattedTime)
@@ -23,7 +29,14 @@ func main() {
return
}
- fmt.Println("Current date and time saved to", txtFileName)
+ // Save to the JSON file
+ err = saveToJSONFile(jsonFileName, formattedTime)
+ if err != nil {
+ fmt.Println("Error saving to JSON file:", err)
+ return
+ }
+
+ fmt.Println("Current date and time saved to", txtFileName, "and", jsonFileName)
}
func saveToTextFile(fileName string, data string) error {
@@ -38,3 +51,27 @@ func saveToTextFile(fileName string, data string) error {
_, err = file.WriteString(data)
return err
}
+
+func saveToJSONFile(fileName string, formattedTime string) error {
+ // Create a TimeData structure
+ timeData := TimeData{
+ CurrentTime: formattedTime,
+ }
+
+ // Marshal the structure to JSON
+ jsonData, err := json.MarshalIndent(timeData, "", " ")
+ if err != nil {
+ return err
+ }
+
+ // Open the file for writing (create it if it doesn't exist)
+ file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+
+ // Write the JSON data to the file
+ _, err = file.Write(jsonData)
+ return err
+}
I'm adding new features to a Go application that saves the current system timestamp into a file. Write a commit summary that describes the changes above.
Response
Of course. Here is a commit summary that follows the conventional commit standard:
feat(output): add support for JSON output
In addition to the plain text file, the application now saves the current timestamp to a `current_time.json` file.
This provides a structured data format, making the output easier for other programs to parse and consume. A new `saveToJSONFile` function and a `TimeData` struct have been added to handle the JSON marshaling and file writing.
|
| Model: |
gemini-2.5-pro |
| Temperature: |
0.2 |
| Max output tokens: |
8192 |
| TopK: |
40.0 |
| TopP: |
0.95 |
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-13 UTC.
[null,null,["Last updated 2026-06-13 UTC."],[],[]]