-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb25cab
commit 5421151
Showing
6 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package metrics | ||
|
||
// initTables ensures that the tables required exist and have the correct columns present | ||
func (m *Metrics) initTables() error { | ||
if m.mysqlClient == nil { | ||
return nil | ||
} | ||
query := "CREATE TABLE IF NOT EXISTS `asn` (" + | ||
" `asn` int unsigned NOT NULL," + | ||
" `organization` VARCHAR(255) NOT NULL," + | ||
" `count` int unsigned NOT NULL," + | ||
"UNIQUE KEY `asn-unique` (`asn`)" + | ||
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;" | ||
|
||
result, err := m.mysqlClient.Query(query) | ||
if err != nil { | ||
return err | ||
} | ||
return result.Close() | ||
} | ||
|
||
// DeleteASNRecords deletes all records from the asn table in the database | ||
func (m *Metrics) DeleteASNRecords() error { | ||
if m.mysqlClient == nil { | ||
return nil | ||
} | ||
query := "DELETE from asn;" | ||
result, err := m.mysqlClient.Query(query) | ||
if err != nil { | ||
return err | ||
} | ||
return result.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters