草庐IT

javascript - 使用 index.ts 文件导出类导致注入(inject)的构造函数中未定义

我使用index.ts文件来封装导出,如Angular2样式指南(https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure)中所述。这在我编写的应用程序中运行良好,但出于某种原因,在我尝试注入(inject)另一项服务的一项服务中,这会导致奇怪的错误。导出类:import{Injectable}from"angular2/core";@Injectable()exportclassUserIds{private_signature_id:string;pri

javascript - Gulp-inject 转换不起作用

我尝试设置gulp-inject以将依赖项注入(inject)index.html。除了转换功能外,一切正常。我需要按以下方式替换部分文件路径:/frontend/src/-->/static/我试过这样做(从某处复制粘贴):transform:function(filePath,file,i,length){varnewPath=filePath.replace('/frontend/src','');console.log('injectscript='+newPath);return'';}执行后,控制台中没有任何内容(标准gulp输出除外),结果文件中出现未转换的文件路径。看起

注入(inject) URL 的 Javascript

我们有一个相对受欢迎的网站,最近我们开始看到一些奇怪的URL在我们的日志中弹出。我们的页面引用了jQuery,我们开始看到这些脚本的片段被插入到URL中。所以我们有这样的日志条目:/js/,data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?d(请求的用户代理字符串是Java/1.6.0_06,所以我认为我们可以安全地假设它是一个可能用Java编写的机器人。另外,我可以在jQuery文件中找回那段附加代码。现在,我的问题是为什么机器人会尝试

javascript - 如何将模拟服务注入(inject)过滤器的单元测试?

我有一个简单的angularjs过滤器(它需要一个id并将其转换为名称字符串),它依赖于自定义服务来完成它的工作:angular.module('app').filter('idToName',function(User){returnfunction(id){varresult,user;result='';if(id){result='nonamefound';user=User.getById(id);if(user){result=user.firstName;}}returnresult;};});我想为它写一个单元测试。我希望能够将用户服务的模拟注入(inject)到测试中

go - 接口(interface)依赖注入(inject)问题

我有提供一些tcp连接工作的包,基本上是这样的:packageconnpoolimport("io/ioutil""net/http")typeConnPoolstruct{}func(pool*ConnPool)GetConn()Conn{returnConn{}}func(pool*ConnPool)ReleaseConnection(connConn){}typeConnstruct{}func(cConn)FetchUrl(urlstring)([]byte,error){req,err:=http.NewRequest("GET",url,nil)iferr!=nil{ret

go - 注入(inject)带有变量的字符串模板

我正在看这篇文章:https://medium.com/@IndianGuru/understanding-go-s-template-package-c5307758fab0我想知道如何使用模板将变量注入(inject)字符串,例如:funcgetTemplate(vstring)string{return`CREATETABLEshare_${v}PARTITIONOFshareFORVALUESIN(${v});`}文章中的示例将输出写入标准输出,但我需要将模板的结果存储为变量,有人知道怎么做吗?类似于:result:=getTemplate("0")

go - 嵌套依赖注入(inject)在 golang 中是否可以接受?

嵌套依赖注入(inject)有什么问题吗?例如:typeParentServicestruct{db*sql.DB}typeUsefulChildStructstruct{attrAintattrBintdb*sql.Db}funcNewParent(db*sql.DB)*ParentService{return&ParentService{db:db}}func(p*ParentService)NewChild()*UsefulChildStruct{return&UsefulChildStruct{db:p.db}}func(c*UsefulChildStruct)DoSometh

go - 通过注入(inject)类型查找 slice 元素的模式

我尝试使用对象的类型在接口(interface)slice中查找对象。我目前的解决方案如下所示:packagemainimport("errors""fmt")typeEntitystruct{children[]Childable}func(e*Entity)ChildByInterface(linterface{})(Childable,error){for_,c:=rangee.children{iffmt.Sprintf("%T",c)==fmt.Sprintf("%T",l){returnc,nil}}returnnil,errors.New("childdoesn'texi

git - 在 dockerfile 中的 go build 命令中注入(inject)或插入多个 ENV 变量

我正在使用dockerfile来构建go代码,并且我试图在-ldflags选项中传递3个选项。其中两个标志来自ENV变量,我必须通过字符串插值或连接将它们注入(inject)-ldflags内容,但我不知道如何。目标是在main.go的两个变量中注入(inject)gitrevisionhash和当前时间戳可以通过creatingafilefromdockerfile来完成使用“echo”命令,但我想确保使用简单的变量插值/连接是不可能的ENVGIT_REVISION$(gitrev-parse--shortHEAD)ENVCOMPILATION_TIMESTAMP$(date+%Y%

go - Go中如何实现依赖注入(inject)

我正在将应用程序从Play(Scala)移植到Go并想知道如何实现依赖注入(inject)。在Scala中,我使用了蛋糕模式,而在Go中,我实现了一个DAO接口(interface)以及一个Mongo实现。下面是我如何尝试实现一种模式,让我可以根据需要更改DAO实现(例如测试、不同的数据库等):1。实体.gopackagemodelsimport("time""gopkg.in/mgo.v2/bson")type(Entitystruct{Idbson.ObjectId`json:"id,omitempty"bson:"_id,omitempty"`CreatedAttime.Time