Path of the guide package in Golang

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

A note on the path mentioned in Go Web programming:

1 Relative paths

Import ". Model"//<--is the model directory of the same directory as the current file, but it is not recommended to use this method to guide the package

2 Absolute path

Import "Shortcut/model"//<--load Gopath/src/shortulr/model module

Point operation
We sometimes see the following ways to import packages

Import (. "FMT")

This point operation means that after the package is imported, you can omit the prefix's package name when you call the package's function, which is the FMT you used earlier. Println ("Hello World") can be omitted written in Println ("Hello World"), no-smell video on the recommendation not to use such a way, poor readability

alias operation
Alias operation as the name implies, we can name the package another one that we remember easily.
import (F "FMT") when calling the package function, the prefix becomes our prefix, that is, F. Println ("Hello World"), personally do not like this way, good System package call name you changed, other people read the code much uncomfortable _ Operation
Import (
"Database/sql"
_ "GitHub. com/z iutek/mymysql/godrv "//<----very Important thank you, thank God, I know what this crap means.
) _ operation is actually to introduce the package, instead of directly using the function inside the package, instead of calling the INIT function inside the package






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.