How to import local files in Go? - import

I would like to organize my Go code into smaller chunks. Lets assume I am writing a web application that follows the MVC pattern. I would like to organize my code like this:
main.go
controllers/whatever/whatever.go
models/whateverelse/whateverelse.go
And than in main.go I would like to:
import "controllers/whatever"
Is this possible with Go? It seems the only option, that does not make too much sense is to put the the files into the GOPATH/src folder. In that case I need to set the git repository to track the $GOPATH/ instead of just tracking my project that is $GOPATH/src/github/username/project.

The solution you have could definitely work if you have the standard github directory structure. However, I would like to point out that to import a go library, you just need to specify the path to that library starting from the directory below src.
If your project library has the path:
src/yourproject1/controllers
and your main code has the path:
src/yourproject2/main.go
In main.go, you simply need to say:
import "yourproject1/controllers"

The solution came from IRC thanks to jaw22:
import "github.com/yoursuername/yourproject/yourlib"

Related

How can I import example project inside of pub-get packages in flutter

Some of pub-get packages have example project inside of the project.
and I search for how to import example project.
most of answer is add path:../
but that doesn't work for me
camerawesome:
path: ../
makes error : Can't find the pubspec.yaml file in /Users/user_name/workspace/flutter-workspace
How can I import example project
flutter create example and copy the source is the only way?
example source looks like import using underbar directory, this is also not make sense for me.
import 'package:camerawesome_example/widgets/top_bar.dart';
Thanks for read my question !!
you want import example code to your project, just like a third lib ?
the example project not real part of lib. you cant just import the code to
your code for use. it's not design for that. it's just show how to use lib.

Target of URI doesn't exist: 'theme.dart', 'colors.dart', 'ink_well.dart', etc

Currently trying to run an example of a guitar tuner created with the 'flutter_fft' plugin, however, I'm receiving an error on some of my imports. I can see that all of these files exist inside my flutter folder but can't seem to access them?
Here are my imports and the error I am receivingmy imports and the error I am receiving
But as you can see in this screenshot I do have all of those files available somewhere on my PC, and the material.dart import works fine?
I've been trying to work this out for a while but after asking a question here the other day and getting an almost immediate, and extremely helpful response, I've decided to come here again. Thanks in advance.
When importing from a package (like flutter) you must first specify the package with a package: and then the path to the imports.
If you don't specify this, dart will assume you are trying to import a file on the same directory as the current file.
so instead of import 'button_style.dart'; it should be import package:flutter/src/material/button_style.dart.
The above will work, but I will let you know that the sole purpose of importing package:flutter/material.dart; is to automatically import every file inside the material directory, and so, all of your imports are useless if you already import material.dart.

How to import all Dart files from a Directory?

I am new to dart so please bear with me if this is really bad question. I am developing an app using flutter, and I have one question. I have many screens in my app, like About the App, Homepage, Upcoming Events, etc. I have kept all these screens in a folder in lib/screens directory. And to import them in main.dart for routes I have to import each and every file, like
import "screens/homepage.dart";
import "screens/aboutTheApp.dart";
import "screens/upcomingEvents.dart";
Is there a simpler way to do it? Is there a way to import the "screens" directory at once?
I have tried to import the complete folder and tried making it a package, but it isn't helping.
You can create a file in the screens directory and call it all.dart or whatever you like. In this file, you will simply export all of the Dart files in that folder:
export 'homepage.dart';
export 'aboutTheApp.dart';
export 'upcomingEvents.dart';
Now, whenever you want to use any file from that folder, you can just import all.dart or what you called it:
import 'screens/all.dart`;
...
Other than that, there is no possibility to import a directory.
No, there is no simpler way.
Dart do not offer a directory import.
No, there is no direct way to automatically include all .dart files from a directory. You should be able to use some form of code generation (e.g. with source_gen or build) to generate a .dart file at build-time that other files could import.
I create a package to auto export all dart files.
I named it auto_exporter you can search it on https://pub.dev/packages
when you are creating a dart package I think it's useful.

Angular2 & TypeScript importing of node_modules

I had a very simple 'hello world' Angular2 app. I also made the apparently unreasonable decision to work with different directory structures between my dev project and the final deployment folder on my spring backend.
Because of this difference, I had an issue with the TypeScript imports, and this line ended up producing 404 errors (unable to find /angular2/core library) when I tried to open the actual app in my browser:
import {Component, View} from 'angular2/core';
So long story short, I ended up adding back the /app folder to make everything work, but I ended up modifying my import statements as follows:
import {Component, View} from '../node_modules/angular2/core';
This, however, turned out to cause some weird behavior. For some reason specifying ../node_modules in the library paths is causing the JS to actually load ALL Angular2 files from scratch using ajax calls to retrieve each and every individual file from the npm_modules/angular2/ folder even though this was part of my HTML header:
<script src="/node_modules/angular2/bundles/angular2.dev.js"></script>
When I finally realized what's going on I reverted the import statement back to
import {Component, View} from 'angular2/core';
and it all worked. Angular2 was now completely loaded from the script tag above and there were no files getting loaded by extra ajax calls.
Can someone please explain what is causing this? I assume it's normal behavior but I don't understand how the importing works and why specifying a more detailed path makes such a difference.
The import rules of TypeScript follow the same convention as node.js. If an import begins with a dot:
import {Something} from './some/path';
Then it is treated as a relative path from the file that declares the import. If however it is an absolute path:
import {Component} from 'angular2/core';
Then it is assumed to be an external module, so Typescript will walk up the tree looking for a package.json file, then go into the node_modules folder, and find a folder with the same name as the import, then looks in the package.json of the module for the main .d.ts or .ts file, and then loads that, or will look for a file that has the same name as the one specified, or an index.d.ts or index.ts file.
Wow that seems complex when written out, and there are still some exceptions there... But all in all, if you have worked with node.js before then this should behave exactly the same way.
One thing to note is that there is a TypeScript compiler option that should be set for typing resolutions to work in this way
in tsconfig.json
"moduleResolution": "node"
Now the second part of your question was how does this get loaded without using ajax calls. This is a feature of System.js. The script tag that is loaded in the index.html file imports a bundle which registers the angular2 bundle with System. Once this has happened System knows about these files and correctly assigns them to their references. It's a pretty deep topic but a lot of information can be found either in the README of systemjs, or systemjs-builder.

Flash Builder 4 import services .as files

I am working on a shared project in Flash Builder 4. Our data is coming through web services. We have put the generated .as files into vss so that we can share them. What I can't figure out is how to import those files. I see the files that others have created under my services directory but I can't figure out how to get them to appear in my Data/Services view. Does anybody know how to do this?
It looks like this information is in a file with an .fml extension. This is located in your project.model directory. Besides the fact that you can't get to that file from within flash builder to check it out, I don't know that it is a good idea to source control a project file. We are looking at what options we have to help everyone maintain these service files.