Been trying for the last few days to get rid of "invalid import path:"Atom First project/main/Extension" (build)" error when installing my main.go file but i haven't been able to find the reason behind the error.
OS - Windows 10
IDE - Atom
GOBIN - E:\Github Repository\Programming\Golang\bin
GOPATH - E:\Github Repository\Programming\Golang
File DIR- E:\Github Repository\Programming\Golang\src\Atom First project\main\main.go
E:\Github Repository\Programming\Golang\src\Atom First project\main\Extension/foo.go
main.go
package main
import (
"Atom First project/main/Extension"
)
func main() {
Extension.Extend()
}
foo.go
package Extension
import (
"fmt"
)
func Extend(){
fmt.Println("Hello from Extend func")
}
It's simple: import paths cannot contain spaces. Spec: Import declarations:
Implementation restriction: A compiler may restrict ImportPaths to non-empty strings using only characters belonging to Unicode's L, M, N, P, and S general categories (the Graphic characters without spaces) and may also exclude the characters !"#$%&'()*,:;<=>?[]^`{|} and the Unicode replacement character U+FFFD.
Simply rename your Atom First project folder to e.g. atom-first-project, and change the import declaration.
import (
"atom-first-project/main/Extension"
)
Also note that the package name (which is usually the folder name but not necessarily) must be a valid Go identifier. Spec: Package clause:
A package clause begins each source file and defines the package to which the file belongs.
PackageClause = "package" PackageName .
PackageName = identifier .
Related
the code is:
import (
"context"
"crypto/tls"
"time"
"go.etcd.io/etcd/clientv3"
)
func main(){
...
config := clientv3.Config{}
config.Username = u.username
...
}
go.mod file
module github.com/xxx
go 1.17
require (
github.com/coreos/etcd v2.3.8+incompatible // indirect
go.etcd.io/etcd v2.3.8+incompatible // indirect
)
It fails with this message:
config.Username undefined (type clientv3.Config has no field or method Username)
Is there a way to resolve this problem?what's the difference between github.com/coreos/etcd/clientv3 and go.etcd.io/etcd?
go.etcd.io/etcd/clientv3 and go.etcd.io/etcd/client/v3 are, somewhat confusingly, distinct packages that both use the package name clientv3.
The client/v3.Config type has the Username field you expect, so perhaps you can update your code to import that package instead of the other one?
import (
…
"go.etcd.io/etcd/client/v3"
)
(https://play.golang.org/p/2SK2FUNxWs9)
github.com/coreos/etcd/clientv3 was an older name for the package from the github.com/coreos/etcd repo before they adopted Go modules. When they moved to modules, they changed the canonical import path to go.etcd.io/etcd/client/v3, but (through some quirks of the Go module system) a hybrid of the old and new paths can still be resolved, using the code from the old path but served from the new URL. You probably want to use only the new canonical path.
I am still learning python but got stuck here:
from pathlib import Path
import os
import shutil
p = Path.home()
shutil.copy(p / 'G:\souce.txt', p / 'G:\dest.text')
The error is:
shutil: shutil
Anomalous backslash in string: '\s'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Anomalous backslash in string: '\d'. String constant might be missing an r prefix.pylint(anomalous-
backslash-in-string)
Module 'shutil' has no 'copy' memberpylint(no-member)
Not able to go for the next step. So any suggestions please.
You can just do:
import shutil
shutil.copy('G:\souce.txt', 'G:\dest.text')
This a section in a schema file
imports:
- path: configs/folder1/resources/gcpresource/test/*
I am trying to import all the files in a folder using the template's schema file.
I know that this does not work.
My question is,
what is a better way to import all the files using * or something that's suitable so that deployment manager can import all of the files in a folder without having to explicitly specify them ?
You could do so in python if they are all yaml config files
# my-template.yaml
imports:
- path: omni-importer.py
And in the middleware-like python template do something like:
# omni-importer.py
import yaml
from os import listdir
from os.path import isfile, join
def generate_config(ctx):
mypath = ctx.properties['path']
files = [f for f in listdir(mypath) if isfile(join(mypath, f)) and f.endswith('yaml')]
yamls = map(lambda f: yaml.load(open('test.txt')['resources']), files)
return {
'resources': yamls,
}
This is not working code, but rather a proof of concept
I'm writing Scala code. What is the correct path schema for writing a URI when using Rapture to operate with files on Windows? I have added the following dependencies:
libraryDependencies += "com.propensive" %% "rapture" % "2.0.0-M3" exclude("com.propensive","rapture-json-lift_2.11")
Here is part of my code:
import rapture.uri._
import rapture.io._
val file = uri"file:///C:/opt/eric/spark-demo"
file.delete()
but I got the message:
Error:(17, 16) value file is not a member of object rapture.uri.UriContext
val file = uri"file:///C:/opt/eric/spark-demo"
or I tried this one:
val file = uri"file://opt/eric/spark-demo"
The same error:
Error:(17, 16) value file is not a member of object rapture.uri.UriContext
val file = uri"file://opt/eric/spark-demo"
And my local path is:
C:\opt\eric\spark-demo
How can I avoid the error?
You're missing an import:
import rapture.io._
import rapture.uri._
import rapture.fs._
val file = uri"file:///C:/opt/eric/spark-demo"
file.delete()
rapture.fs is the package defining an EnrichedFileUriContext implicit class, which is what the uri macro trys to build when being provided with a file URI scheme.
I am prototyping a meta model on top of proto3. To generate domain specific boilerplate as the go proto3 extension syntax is ridiculously expressive. My domain proto files depend on meta.proto which contain the extensions.
I can compile the these to go. When including the meta.proto file the generated go ends up with the following include block:
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "google/protobuf" <--- this import does not exist !!
My extension file has the following structure(based off this):
syntax = "proto2";
package "...";
option go_package = "...";
import "google/protobuf/descriptor.proto"; <--- this causes the import
// message MyExtensionClass ...
// message MyExtensionField ...
extend google.protobuf.MessageOptions {
optional MyExtensionClass class = 50000;
}
extend google.protobuf.FieldOptions {
optional MyExtensionField field = 50001;
}
I know the solution is likely very simple, the google/protobuf include is meant for C++ generation.
In my workspace the included package should be "github.com/golang/protobuf/protoc-gen-go/descriptor"
Poor mans solution. Not ideal, directing it to the relevant go import works:
sed -i '' -e 's/import google_protobuf \"google\/protobuf\"/import google_protobuf \"github.com\/golang\/protobuf\/protoc-gen-go\/descriptor\"/g' pkg/domain/proto/extensions/*.pb.go