我对Golang很新,并试图使一个简单的REST API应用程序工作.
最初,一切都很好,因为我将所有代码放在main
包下的同一目录中.
但是,现在我处于一个需要开始将代码重构为子目录和包的阶段.不幸的是,我无法成功编译应用程序.
我GOPATH
的设置为:~/.workspace
当前的应用程序位于:~/.workspace/src/gitlab.com/myapp/api-auth
这就是我目前的代码组织:
这是我的 main.go
package main
import (
"net/http"
"os"
"strings"
"github.com/gorilla/context"
"github.com/justinas/alice"
"gopkg.in/mgo.v2"
"gitlab.com/myapp/api-auth/middlewares"
)
func main() {
privateKey := []byte(strings.Replace(os.Getenv("JWT_KEY"), "\\n", "\n", -1))
conn, err := mgo.Dial(os.Getenv("MONGO_CONN"))
if err != nil {
panic(err)
}
defer conn.Close()
conn.SetMode(mgo.Monotonic, true)
ctx := appContext{
conn.DB(os.Getenv("MONGO_DB")),
privateKey,
}
err = ctx.db.C("users").EnsureIndex(mgo.Index{
Key: []string{"username"},
Unique: true,
Background: true,
Sparse: false,
})
if err != nil {
panic(err)
}
commonHandlers := alice.New(LoggingHandler, context.ClearHandler, …
Run Code Online (Sandbox Code Playgroud) 我试图解析RFC1123格式的日期(星期四,2010年1月21日17:47:00美国东部时间).
这是我尝试但没有奏效的:
DateTime Date = DateTime.Parse(dt);
DateTime Date = DateTime.ParseExact(dt, "r", null);
Run Code Online (Sandbox Code Playgroud) 可能重复:
使用CLR中的'as'关键字进行转换
我在C#中看到了两种不同的方式.
例如:
MyObj foo = (MyObj) bar; // this is what I see most of the times
MyObj foo = bar as MyObj; // I do see this sometimes
Run Code Online (Sandbox Code Playgroud)
style 1
和style 2
铸造的专有名称?非常感谢您对此进行调查:)
该grunt-wiedep
任务输出资产的相对路径.我需要绝对路径.所以,我replace
按照这里的建议重新配置了这个块:https://github.com/stephenplusplus/grunt-wiredep/issues/46
但是,在replace
按照建议指定块之后,我将以下内容添加为我的脚本引用.如你所见,这是错误的.
<script src="/../../../public/vendors/jquery/dist/jquery.js"></script>
<script src="/../../../public/vendors/angular/angular.js"></script>
<script src="/../../../public/vendors/angular-resource/angular-resource.js"></script>
<script src="/../../../public/vendors/angular-route/angular-route.js"></script>
Run Code Online (Sandbox Code Playgroud)
我想要的是这样:
<script src="/vendors/jquery/dist/jquery.js"></script>
<script src="/vendors/angular/angular.js"></script>
<script src="/vendors/angular-resource/angular-resource.js"></script>
<script src="/vendors/angular-route/angular-route.js"></script>
Run Code Online (Sandbox Code Playgroud)
所以,我尝试了这个替换块.注意RegEx
:
replace: {
js: '<script src="/{{filePath}}"></script>'.replace(/\.\.\/public/gi, ''),
css: '<link rel="stylesheet" href="/{{filePath}}" />'.replace(/\.\.\/public/gi, '')
}
Run Code Online (Sandbox Code Playgroud)
但它似乎{{filePath}}
在以后被替换,因此RegEx
不会产生预期的结果.
处理这种情况的理想方法是什么?
我正在重建我的DEV图像,我不再能够在VS Extensions Gallery上找到这两个很棒的插件:结构装饰,AllMargins
有什么想法他们去了哪里?我可以使用任何替代品吗?在最坏的情况下,是否可以在我的旧图像中从我的VS 2010中提取结构装饰并将其安装到新图像中?
甚至无法想象在没有漂亮的垂直线的情况下经历数千行代码!
我正在尝试使用Stripe API收取申请费.我确信我在请求中遗漏了一些东西.
条带投诉它需要以下任一项:OAuth密钥,Stripe-Account标头或目标参数.
我正在传球Stripe-Account
.
你能指点我正确的方向吗?
这是我的卷曲请求:
curl https://api.stripe.com/v1/charges \
-u sk_test_<key>: \
-H "Stripe-Account: acct_<key>" \
-d amount=2000 -d currency=usd -d capture=true \
-d card=tok_<key> -d description="curl" -d application_fee=48
Run Code Online (Sandbox Code Playgroud)
以下是我得到的回复:
{
"error": {
"type": "invalid_request_error",
"message": "Can only apply an application_fee when the request is made on behalf of another account (using an OAuth key, the Stripe-Account header, or the destination parameter).",
"param": "application_fee"
}
}
Run Code Online (Sandbox Code Playgroud) 我是单元测试和模拟概念的新手.我试图弄清楚如何为下面的基本开箱即用用户注册代码编写一个好的测试用例:
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
以下是我需要您的意见/帮助的一些具体要点:
我在ASP .Net MVC 4项目中使用Autofac for IoC.Autofac在初始化存储库并将其传递给API控制器时遇到一些问题.
我确信我的配置中缺少一些东西.
这是我导航到的错误: https://localhost:44305/api/integration
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'
on type 'EL.Web.Controllers.API.IntegrationController' can be invoked with
the available services and parameters: Cannot resolve parameter
'EL.Web.Infrastructure.IRepository`1[EL.Web.Models.Integration] repository' of
constructor 'Void .ctor(EL.Web.Infrastructure.IRepository`1[EL.Web.Models.Integration])'.
</ExceptionMessage>
<ExceptionType>Autofac.Core.DependencyResolutionException</ExceptionType>
<StackTrace>
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Execute()
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 …
Run Code Online (Sandbox Code Playgroud) 大多数情况下,在对某些数据进行排序时,我们有两种选择:
你什么时候用一个而不是为什么?
出于某种原因,我的SharePoint模式对话框无法正常工作.我得到的错误是这样的:
SP.UI.$create_DialogOptions is not a function
Object doesn't support this property or method
这是我的代码:
var options = SP.UI.$create_DialogOptions();
options.width = 525;
options.height = 300;
options.url = '/_layouts/mywork/richtexteditor.aspx';
options.dialogReturnValueCallback = Function.createDelegate(null, function (result, value)
{
alert(result + value);
});
SP.UI.ModalDialog.showModalDialog(options);
Run Code Online (Sandbox Code Playgroud)
有趣的是,当我在Firebug中检查SP.UI时,我没有看到所有的方法和属性.
注意:我使用的是标准Webpart(非可视化),而不是应用程序页面.
c# ×2
.net ×1
asp.net-mvc ×1
autofac ×1
bower ×1
casting ×1
datetime ×1
go ×1
gruntjs ×1
mocking ×1
performance ×1
rfc1123 ×1
sharepoint ×1
sorting ×1
sql ×1
unit-testing ×1
wiredep ×1