在Go语言中如何将C和Python代码串联起来?

huangapple go评论173阅读模式
英文:

Stringing together C and Python code in Go?

问题

我正在尝试创建一个简单的Go函数,它将接收一个reddit风格的Markdown字符串,并返回相应的HTML。

目前,我知道需要先安装Discount,并且reddit使用以下三个文件作为Discount的包装器:

基于此,有人知道我如何使用Cgo和go-python将所有这些组合在一起,创建一个简单的Markdown函数吗?(与reddit源代码的其他部分无关)

英文:

Update


I'm trying to create a simple Go function which will simply take in a string of reddit-style Markdown and return the appropriate HTML.

Right now, I know that having Discount installed is a prerequisite and that at least the following three files are used by reddit as wrappers around Discount:

Based on this, does anyone know how I can sort of glue all this together with Cgo and go-python to create a simple Markdown function? (independent of the rest of the reddit source code)

答案1

得分: 3

如果你只需要Markdown,我不明白Python如何适用于此。也许还有其他原因,但如果可能的话,你应该避免使用Python。如果有使用Python的原因不在问题中,我可以编辑这个答案并解决这个问题。

首先,尝试使用这个原生的Go Markdown包:https://github.com/knieriem/markdown

如果那不起作用,下一个最简单的方法是使用Discount(或任何其他用C编写的Markdown库,比如GitHub的Upskirt分支)并用cgo或SWIG进行封装。

英文:

If all you want is Markdown, I don't see how Python fits into this. Maybe there's more to it, but if at all possible you should leave Python out of this. If there's a reason to use Python that wasn't in the question, I can edit this answer and address that.

First, try this native Go Markdown package: https://github.com/knieriem/markdown

If that doesn't work, the next easiest thing is to take Discount (or any other Markdown library written in C, such as GitHub's Upskirt fork) and wrap it with cgo or SWIG.

huangapple
  • 本文由 发表于 2011年5月22日 23:50:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/6089041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定