小编Moo*_*oon的帖子

如何从Golang中的子目录正确导入包?

我对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)

go

12
推荐指数
1
解决办法
1万
查看次数

在C#,.NET 4.0中解析RFC1123格式的日期

我试图解析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)

c# datetime rfc1123

11
推荐指数
1
解决办法
5201
查看次数

C#不同的铸造方式 - (T)obj vs obj as T

可能重复:
使用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 1style 2铸造的专有名称?
  • 我如何决定何时使用什么?
  • 有任何重大的性能问题吗?
  • 我还应该知道与此主题相关的其他内容吗?

非常感谢您对此进行调查:)

.net c# casting

11
推荐指数
1
解决办法
6317
查看次数

使用grunt-wiredep为Grunt + Bower提供的绝对路径

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不会产生预期的结果.

处理这种情况的理想方法是什么?

gruntjs bower bower-install grunt-wiredep wiredep

11
推荐指数
2
解决办法
7189
查看次数

VS 2010扩展 - 缺少结构装饰和AllMargins插件

我正在重建我的DEV图像,我不再能够在VS Extensions Gallery上找到这两个很棒的插件:结构装饰,AllMargins

有什么想法他们去了哪里?我可以使用任何替代品吗?在最坏的情况下,是否可以在我的旧图像中从我的VS 2010中提取结构装饰并将其安装到新图像中?

甚至无法想象在没有漂亮的垂直线的情况下经历数千行代码!

visual-studio-2010 visual-studio visual-studio-extensions

10
推荐指数
3
解决办法
2558
查看次数

传递application_fee时出现Stripe API错误

我正在尝试使用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)

stripe-payments stripe-connect

9
推荐指数
1
解决办法
3839
查看次数

ASP .Net MVC 3:单元测试控制器动作

我是单元测试和模拟概念的新手.我试图弄清楚如何为下面的基本开箱即用用户注册代码编写一个好的测试用例:

[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)

以下是我需要您的意见/帮助的一些具体要点:

  1. 我不一定想在ASP .Net成员资格数据库中创建新用户.
  2. 根据传入的模型,如何确保用户成功注册或过程中出现错误.

asp.net-mvc unit-testing mocking asp.net-mvc-3

8
推荐指数
1
解决办法
8159
查看次数

Autofac和ASP .Net MVC 4 Web API

我在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)

autofac asp.net-mvc-4 asp.net-web-api sharepoint-2013

8
推荐指数
1
解决办法
1万
查看次数

SQL排序:服务器与客户端

大多数情况下,在对某些数据进行排序时,我们有两种选择:

  1. 在SQL服务器上排序 - 使用ORDER BY子句
  2. 在客户端排序我们从数据库中获取数据

你什么时候用一个而不是为什么?

sql sorting performance

7
推荐指数
3
解决办法
1628
查看次数

SharePoint 2010:创建模态对话框时出现JavaScript错误?

出于某种原因,我的SharePoint模式对话框无法正常工作.我得到的错误是这样的:

  • 在Firefox中: SP.UI.$create_DialogOptions is not a function
  • 在IE中: 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(非可视化),而不是应用程序页面.

sharepoint sharepoint-2010 sharepoint-clientobject

7
推荐指数
1
解决办法
3万
查看次数