This Go program demonstrates the use of structs and functions as struct methods stored in a saparated package to get string inputs from the user and save all the information in a json file with pre-determined json field names created by using struct tags.
When run, the program will ask the user to input a note title. After pressing the Enter
key, the user will then be asked to input the note content. Both the title and content can be typed in freely as the program stores them as strings.
After inputting the note content, the program will show a message to confirm the note title and its content as given by the user. Then, the program will attempt to save the information as a json
file. The saved json
file contains three fields: title
, content
, and created_at
. The timestampt in the field created_at
will be generated automatically by the program.
The codes of this projects are organized into the code for the main program (stored in the main.go
file) and the codes for struct methods to display and save user inputs stored in the note.go
file as a separate package.
- The user inputs the note title as a string
- The user inputs the note content as a string
- The program takes those inputs to create a struct which stores the note title, content, and the timestamp at its creation
- The program displays messages to confirm the title and the content from the inputs
- The program displays a message to notify the user that it's saving the note
- The program attempts to save the inputs as a
json
file with json field names according to the struct tags given in the code - The program displays the message that it saves the file successfully