Answer the question
In order to leave comments, you need to log in
How to organize code on GO?
How to write code
has examples of creating your own package.
The application works with MySQL and consists of main.go and a pair of package.
The question is how to make it so that there is one variable (or a package with a getter method) containing a connection to MySQL and it can be accessed from packages.
Answer the question
In order to leave comments, you need to log in
In its simplest form, you can do this:
you create a package, for example db, in which you work with the connection. Here, create a reference variable to *sql.DB. You
create a regular public function that returns this variable.
More or less like this:
var connection *sql.DB
func GetConnection() *sql.DB {
return connection
}
func GetConnection() *sql.DB {
connection.Ping()
return connection
}
First, we need to read the documentation and make sure everything works correctly...
Try writing a form with this solution:
<form id="myForm">
<input id='experience' name="experience" value=""/>
<input type="submit" value="Go"/>
</form>
$(function() {
$.validator.addMethod("regex", function(value, element, regexpr) {
return regexpr.test(value);
}, "Пожалуйста, введите верное значение");
$("#myForm").validate({
rules: {
experience: {
required: true,
regex: /^(\s*)?(\+)?([- _():=+]?\d[- _():=+]?){8,14}(\s*)?$/
}
}
});
});
/
at the beginning and at the end of the regular expression. Those. should turn out like this:regex: '/^(\s*)?(\+)?([- _():=+]?\d[- _():=+]?){8,14}(\s*)?$/',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question