Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
健杭 徐
intern_project_frontend_backend
Commits
6152d12b
Commit
6152d12b
authored
Jun 21, 2025
by
健杭 徐
Browse files
main.go func main createTable
parent
01b4afb5
Changes
1
Hide whitespace changes
Inline
Side-by-side
myproject/chatroom/main.go
View file @
6152d12b
...
@@ -60,6 +60,26 @@ func main() {
...
@@ -60,6 +60,26 @@ func main() {
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
createTable
()
var
tableExists
bool
err
=
db
.
QueryRow
(
`
SELECT EXISTS (
SELECT 1
FROM information_schema.tables
WHERE table_name = 'rooms'
)
`
)
.
Scan
(
&
tableExists
)
if
err
!=
nil
{
log
.
Fatal
(
"Table check failed: "
,
err
)
}
if
!
tableExists
{
log
.
Println
(
"Table 'rooms' not found, creating..."
)
createTable
()
}
else
{
log
.
Println
(
"Table 'rooms' already exists"
)
}
router
:=
gin
.
Default
()
router
:=
gin
.
Default
()
router
.
Use
(
func
(
c
*
gin
.
Context
)
{
router
.
Use
(
func
(
c
*
gin
.
Context
)
{
c
.
Writer
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
c
.
Writer
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment